VB6 connection to SQL 2000

  • I have built an application using SQL 2000 and VB6 that I now want to distribute to sites using only MSDE. I have been trying to work out the best way to install and attach my new database to the MSDE site. Note: I am using MSDE 2000.

    I know I can manually use sp_attach but I want to do it programmatically with VB. I have tried using the SQLDMO object which seems to be OK except it does not accept spaces in the file name and of course the default installation leaves MSDE in \program files\microsoft sql server\mssql\data .... do any of the SQL 2000 service packs solve this problem or is it a restriction? I do not have any installed at present. the code is below.

    Are there better ways to do this? Do you know of any web sites where this is better explained?

    Also I notice that when installing MSDE SQL 2000 it does not ask what type of authentication you wish to use ie. windows or SQL. What does it default to for MSDE?

    Public Function AttachDatabase(DBName As String, FileName1 As String, Filename2 As String) As Boolean

    Dim ErrorString As String

    Dim oSvroot As Object

    Dim lsExecute

    Set oSvroot = CreateObject("SQLDMO.SQLServer")

    On Error GoTo AttachError

    'Set the time out fairly high.

    'Note this value is in seconds.

    oSvroot.LoginTimeout = 60

    'Connect.

    oSvroot.Connect "(local)", "sa", ""

    'Attach.

    Call oSvroot.AttachDB(DBName, FileName1 & ", " & Filename2)

    AttachDatabase = True

    Exit Function

    wrxguru


    wrxguru

  • For the attach, try wrapping the file name in brackets, like this: "[c:\test data.mdf]". Not sure about MSDE - if nothing else you should be able to alter it via DMO to be whichever you prefer.

    Andy

  • Excellent. That trick seems to work ([]). Not sure why you would have to do that but anyway, thanks Robin

    wrxguru


    wrxguru

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply