Vb6 to Connect With SQLEXPRESS

Hi

I am trying to connect to sqlexpress from vb6 and getting error: a database with the same name exists,or specified file cannot be opened, or it is located on UNC share.

Using following code

Dim cn As ADODB.Connection
Set cn = New Connection
cn.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"AttachDBFileName=" & App.Path & "\northwnd.mdf;Data Source=.\sqlexpress"
cn.Open

If anyone please help

Zaabdullah



Answer this question

Vb6 to Connect With SQLEXPRESS

  • elinde

    Thank you for help.

    I used this string it worked.

    cn.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;AttachDBFileName=" & App.Path & "\northwnd.mdf;Data Source=.\sqlexpress"

    It worked.

    Thank you

    zaabdullah


  • Exploder

    Try this one instead.

    Set Cn = New ADODB.Connection
    With Cn
    .Provider = "MSDASQL;DRIVER={SQL Server}; " & _

    " SERVER=server\sqlexpress; " & _

    " trusted_connection=no; " & _

    " user id=sa; password=pass; " & _

    " database=Northwind;"
    .Open
    End With

    Server is the name of the computer where SQL Express installed


  • Bill_Henning

    Try "Server=.\SQLExpress" and "Database=xxxx". Go here for details...



  • Vb6 to Connect With SQLEXPRESS