COPYING SQL SERVER 2005 DATABASE

P

Paulin BANTO

Hi

I'm making a program in Access ADP with a SQL server 2005 database.
I Have to write a code wich copy my active database DB1 into a new history
database DB2 on the same Server in DB1 ( .MDF an LDF) folder.
I'have found the following code and i used SQL DMO for that

Public Function CopyDB(ByVal strServer, ByVal strSourceDB As String, ByVal
strDestDB As String)

Dim oSQLServer As SQLDMO.SQLServer2
Dim oDB As SQLDMO.Database2
Dim oTransSpec As SQLDMO.Transfer
Dim dbSrc As New SQLDMO.Database
Set oSQLServer = New SQLDMO.SQLServer2
Set oDB = New SQLDMO.Database2

Set oTransSpec = New SQLDMO.Transfer
With oTransSpec
.DestServer = strServer
.DestDatabase = strDestDB
.DestUseTrustedConnection = True
.CopyAllObjects = True
.CopyData = SQLDMOCopyData_Replace
.DropDestObjectsFirst = True
.Script2Type = SQLDMOScript2_AnsiFile
.CopySchema = True
End With

oSQLServer.LoginSecure = True
oSQLServer.Connect strServer
Set dbSrc = objSQLServerDMO.Databases(strSourceDB)

oSQLServer.Databases.Add oDB
oSQLServer.Databases(strSourceDB).ScriptTransfer oTransSpec
==================================================
oSQLServer.Databases(strSourceDB).Transfer oTransSpec
====================================================
oSQLServer.Disconnect

Set oDB = Nothing
Set dbSrc = Nothing
Set oTransSpec = Nothing
Set oSQLServer = Nothing

End Function

When I execute this code all objet of DB1 are copied in DB2 but this line
( oSQLServer.Databases(strSourceDB).Transfer oTransSpec ) occurs error.
I do not know what to do then as i do not undertand the error.

Can some one help me ?


PS: Please excuse me for my english and for my mistakes. I'm a french
speaking man I do my best to communicate.

Thanks in advance.
 
S

Sylvain Lafontaine

Vous devriez poser votre question dans un groupe discussion francophone au
sujet de SQL-Server; genre « microsoft.public.fr.sqlserver ». Le groupe
m.p.access.adp.sqlserver sert à discuter des problèmes entre ADP et
SQL-Server et ne concernent pas vraiment les questions relevant uniquement
de SQL-Server.

Vous devriez également fournir le message d'erreur rencontré afin de
faciliter la tâche à ceux qui tenteront de vous répondre. Mentionner la
place où vous trouvé le morceau de code ne serait également pas à dédaigner
ainsi que toute autre information pertinente comme par exemple la liste des
objets qui n'auraient pas été transférées.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top