VB "Trusted Connection" to SQL fails

  • I'm trying to connect to a SQL 7 database from VB using a trusted connection.

    Executing the cn.Open command, below, gives the error: "The login <domain-name>\BillS' does not exist". (I can access the database using that account with NT Authentication from Query Analyzer). What am I doing wrong?

    TIA,

    Bill

    Private Sub Command1_Click()

    Dim cn As ADODB.Connection

    ' connect to <domainname>\BillS

    ' account on SQL box

    Set cn = New ADODB.Connection

    cn.Open "Provider=SQLOLEDB.1;Data Source=bills2;Initial catalog=myDB;Trusted_Connection=Yes"

    cn.Execute "sp_password 'bills','teds'"

    cn.Close

    Set cn = Nothing

    End Sub

  • Lots of different ways to build connect strings, here is one that should work:

    Provider=SQLOLEDB.1;Password=test;Persist Security Info=True;User ID=TestUser99;Initial Catalog=master;Data Source=eg

    I use the trick of creating a empty text file, renaming with a .udl extension. Dbl click to get the UI that lets you build the connection and test it. Then rename the file back to .txt, open in notepad, there's the connect string. I've got an article posted about DSN's that also has some coverage of udl's.

    Andy

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

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