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.
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.