Results 1 to 2 of 2

Thread: Connect VB6 to SQL 2005

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    1

    Connect VB6 to SQL 2005

    Hi All

    I am using vb6 and sql server 2005. I’m trying to connect to a database obviously from vb6. I got some code from the net which is
    vb Code:
    1. 'Declaring your database
    2. Public MyDatabase As ADODB.Connection
    3.  
    4. 'Tables into your database
    5. Public MyTable1 As ADODB.Recordset
    6.  
    7. Private Sub Form_Load()
    8.  
    9. 'Set your variables to nothing (just for stability)
    10. Set MyDatabase = Nothing
    11. Set MyTable1 = Nothing
    12.  
    13. 'Connecting to your DB
    14. Set MyDatabase = New ADODB.Connection
    15. Set MyTable1 = New ADODB.Recordset
    16.  
    17. 'Here's where you're to set all your database options
    18. ConnectionString = "Provider=SQLOLEDB.1" _
    19.               & ";User ID=YOUR-E50BC0DF75\nick" _
    20.               & ";Password=" _
    21.               & ";Initial Catalog=vb6sql" _
    22.               & ";Data Source=xxx.x.x.x\YOUR-E50BC0DF75\SQLEXPRESS"
    23.  
    24. 'If your database is in another computer in the local network you can replace 127.0.0.1 with it's ip adress
    25. MyDatabase.Open ConnectionString
    26. MyTable1.CursorLocation = adUseClient
    27. End Sub
    Now I tried running it but get the message

    ‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’� ��’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
    Run-time error ‘-2147467259 (80004005) ‘:

    [DBNETLIB][ConnectionOpen(Connect()).]SQL Server does not exist or access denied.

    ‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’� ��’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
    I don’t know whether I have got a password or not and if I have I don’t know it. I created the database vb6sql just to test the connection. This is all new to me so if someone could explain in easy to understand step’s I would really appreciate it.

    Regards
    Nick
    Last edited by Hack; Sep 26th, 2007 at 06:20 AM. Reason: Added Highlight Tags and Removed IP Address

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width