0
votes

I want to connect to SQL Server from vb6, but I don't know the code.

My provider "somee" gave me this data:

  • SQL Server version: SQL Server 2008 R2 Express
  • SQL Server address: koroikadb.mssql.somee.com
  • Login name: xxxxxx
  • Login password: yyyyyy
  • Connection string: workstation id=koroikadb.mssql.somee.com;packet size=4096;user id=xxxxxx;pwd=yyyyyy;data source=koroikadb.mssql.somee.com;persist security info=False;initial catalog=koroikadb

Thanks

1

1 Answers

0
votes

You will most likely need to install MDAC 2.8. (Microsoft Data Access Components) You can download here: http://www.microsoft.com/en-us/download/details.aspx?id=5793

Once you have that installed, load up your project in the VB6 IDE, and click the following:

Project > Add References >

Check the following:

Microsoft ActiveX Data Objects 2.8 Library

Microsoft ActiveX Data Objects Recordset 2.8 Library

Ok >

Then the following code can be used to connect to MS-SQL Database:

Dim MyDB As New ADODB.Connection
Dim MyRecordset as New ADODB.RecordSet
MyDB.ConnectionString = "workstation id=koroikadb.mssql.somee.com;packet size=4096;user id=xxxxxx;pwd=yyyyyy;data source=koroikadb.mssql.somee.com;persist security info=False;initial catalog=koroikadb" 
MyDB.Open
MyRecordset.Open "SELECT * FROM people",MyDB, adOpenForwardOnly,adLockReadonly
If Not MyRecordset.EOF Then
    Do
        MyRecordset.MoveNext
    Loop Until MyRecordset.EOF
End If
MyRecordset.Close
MyDB.Close
Set MyRecordset = Nothing
Set MyDB = Nothing