PC Review


Reply
Thread Tools Rate Thread

COPYING SQL SERVER 2005 DATABASE

 
 
Paulin BANTO
Guest
Posts: n/a
 
      28th Aug 2008
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.


 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      28th Aug 2008
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.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Paulin BANTO" <(E-Mail Removed)> wrote in message
news:F8D08015-2DE2-4C2E-8CDC-(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection with an SQL Server 2005 database RosH Microsoft Outlook VBA Programming 3 5th Apr 2007 03:48 PM
Copying from one Database to another VB 2005 Ryan Microsoft VB .NET 6 27th Oct 2006 09:26 PM
sql server 2005, visual studio 2005, Debug database? Iwan Petrow Microsoft C# .NET 1 20th Oct 2006 09:09 AM
sql server 2005 database backup? =?iso-8859-1?q?Recep_TARAK=C7I?= Microsoft VB .NET 0 8th Jan 2006 06:17 PM
VS.2005 standard + SQL Server 2005 = database project missing =?Utf-8?B?aGVyYmVydA==?= Microsoft Dot NET 2 17th May 2005 11:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:35 AM.