Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VB6 connection to MSDE

Hi

Could someone please let me know the code for creating a connection to a database called master on a server called Hurley with a password. I'm creating a sql server database with a front end coded in vb6.

Also could you let me know a way of checking if the connection is established.

Thanks very much

Chris

Comments

  • JomacJomac Member Posts: 231
    : Hi
    :
    : Could someone please let me know the code for creating a connection to a database called master on a server called Hurley with a password. I'm creating a sql server database with a front end coded in vb6.
    :
    : Also could you let me know a way of checking if the connection is established.
    :
    : Thanks very much
    :
    : Chris
    :

    If you create a reference to "MS ActiveX Data Objects":
    [code]
    Const sServer As String = "Hurley"
    Const sData As String = "master"
    Const sUser As String = "username here"
    Const sPass As String = "password here"

    Dim oConn As ADODB.Connection
    Set oConn = New ADODB.Connection

    With oConn
    .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & sUser & ";Password=" & sPass & ";Initial Catalog=" & sData & ";Data Source=" & sServer
    Call .Open

    If .State = adStateOpen Then
    Call MsgBox("Connection Opened")
    Else
    Call MsgBox("Connection Failed")
    End If
    End With
    [/code]
    ______
    [size=2][b][blue]J[/blue]omac.[/b][/size]

Sign In or Register to comment.