hi
U Can use Microsoft ActiveX Data Object(ADO).
Open a Standard EXE Project in
VB
Goto Project Menu --> select References
Select the Reference "MICROSOFT ACTIVEX DATA OBJECT x.x" where x.x can be [ 2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8 (all are different versions)]
Select any one version and click ok
Then Try the following code
Sub ConnectToSQL()
Dim ObjSQLCon As ADODB.Connection
Set ObjSQLCon = New ADODB.Connection
ObjSQLCon.Open "Provider=SQLOLEDB;User Id=username;Password=passwd;Data Source=sqlservermachinename;Initial Catalog=dbname"
If ObjSQLCon.State = adStateOpen Then
Msgbox "SQLConnection Opened",vbInformation
Else
MsgBox "SQLConnection Failed"
End If
End Sub
Here in the Open() method of ADODB.Connection Object, these values should be passed correctly else it will not connect.
Provider=SQLOLEDB; 'OLE DB Provider for SQL Server (do not change this value)
Data Source=sqlservermachinename; 'Should be the name of the server in which SQL Server is running
Initial Catalog=dbname; 'Name of the SQLServer Database that u wish to u connect
User Id=username; 'Should be a valid SQL Server username
Password=passwd; 'Should be a valid SQL Server password
Regards,
Raghu