Databases("'+ @dbname +'").StoredProcedures("'+@spname)+'").Script(74077... blab

DHuppe Messages postés 2 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 14 avril 2009 - 8 avril 2009 à 14:45
DHuppe Messages postés 2 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 14 avril 2009 - 14 avril 2009 à 13:54
Salut à tous

J'utilise cette méthode pour scripter les Stored Proc de ma bd.

SET @exec_str
=
'Databases("'+ @dbname
+'").StoredProcedures("'+RTRIM(UPPER(@spname
))+'").Script(74077,"'
+ @filePath
+ @spname
+'.sql")'

EXEC @hr
= sp_OAMethod @object
, @exec_str
, @return
OUT

Le problème est que les caractères accentués sont mal reproduits dans le fichier généré.  Ça donne par exemple "g,n,r," au lieu de "généré".

Quelqu'un peut m'aider ?

J'ai confiance en vous.

Don le québécois

2 réponses

cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
11 avril 2009 à 12:44
Salut,

A priori le problème se situe plus dans l'encodage utilisé pour enregistrer le fichier qu'autre chose.
Quel est l'outil utilisé pour lire/exécuter les scripts ?

/*
coq
MVP Visual C#
CoqBlog
*/
0
DHuppe Messages postés 2 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 14 avril 2009
14 avril 2009 à 13:54
Salut,

Je roule ce script(que j'ai trouvé sur le web) dans MS Query Analyser.  Ça créé des scripts SQL que j'ouvre aussi dans MS Query Analyser :

Voici la procédure que je roule :

Merci !

IF

OBJECT_ID('GenerateSP')
IS
NOT
NULL
DROP
PROC GenerateSPGO

create

PROC GenerateSP
(@server

varchar(30
)
=
null,@uname

varchar(30
)
=
null,@pwd

varchar(30
)
=
null,@dbname

varchar(30
)
=
null,@filePath

varchar(200
))

AS

DECLARE

@object
intDECLARE

@hr
intDECLARE

@return
varchar(200
)DECLARE

@exec_str
varchar(2000
)DECLARE

@spname
sysnameSET

NOCOUNT
ON-- Sets the server to the local server

IF

@server
is
NULL

SELECT @server
=
@@servername-- Sets the database to the current database

IF

@dbname
is
NULL

SELECT @dbname
=
db_name()-- Sets the username to the current user name

IF

@uname
is
NULL

SELECT @uname
=
SYSTEM_USER-- Create an object that points to the SQL Server

EXEC

@hr
= sp_OACreate
'SQLDMO.SQLServer', @object
OUTIF

@hr
<> 0
BEGIN

PRINT
'error create SQLOLE.SQLServer'

RETURNEND

-- Connect to the SQL Server

IF

@pwd
is
NULL

BEGIN

EXEC @hr
= sp_OAMethod @object
,
'Connect',
NULL, @server
, @uname

IF @hr
<> 0

BEGIN

PRINT
'error Connect'

RETURN

END

ENDELSE

BEGIN

EXEC @hr
= sp_OAMethod @object
,
'Connect',
NULL, @server
, @uname
, @pwd

IF @hr
<> 0

BEGIN

PRINT
'error Connect'

RETURN

END

END--Verify the connection

EXEC

@hr
= sp_OAMethod @object
,
'VerifyConnection', @return
OUTIF

@hr
<> 0
BEGIN

PRINT
'error VerifyConnection'

RETURNEND

SET

@exec_str
=
'DECLARE script_cursor CURSOR FOR SELECT name FROM '
+ @dbname
+'..sysobjects WHERE type ''P'' and category 0 ORDER BY Name'EXEC

(@exec_str
)OPEN

script_cursor
FETCH

NEXT
FROM script_cursor
INTO @spname
WHILE

(@@fetch_status
<>
-1
)BEGIN

SET @exec_str
=
'Databases("'+ @dbname
+'").StoredProcedures("'+RTRIM(UPPER(@spname
))+'").Script(74077,"'
+ @filePath
+ @spname
+'.sql")'

EXEC @hr
= sp_OAMethod @object
, @exec_str
, @return
OUT

IF @hr
<> 0

BEGIN

PRINT
'error Script'

RETURN

END

FETCH
NEXT
FROM script_cursor
INTO @spname
END

CLOSE

script_cursor
DEALLOCATE

script_cursor

-- Destroy the object

EXEC

@hr
= sp_OADestroy @object
IF

@hr
<> 0
BEGIN

PRINT
'error destroy object'

RETURNEND

GO
0
Rejoignez-nous