THE Connection in SQL 2000

Asked By 20 points N/A Posted on -
qa-featured

How to make the connection in SQL 2000 with Visual Basic 6 ?

SHARE
Best Answer by juisaha
Best Answer
Best Answer
Answered By 0 points N/A #91307

THE Connection in SQL 2000

qa-featured

It depends on what version of VB you are using, and what version of SQL Server you’re attempting to connect to. Also, there are several ways to connect from each version of VB to each version of SQL Server (ODBC, ADODB, DSN-less, etc.).

Answered By 5 points N/A #91309

THE Connection in SQL 2000

qa-featured

Hi,

The method used to connect your SQL 2000 Database to Visual basic 6 program is called the ADO.NET. The connection can be made using the sql connection object. Here is a sample code to make a connection.

Imports System.Data.SqlClient

Dim CN As SqlConnection

CN = New SqlConnection( “Data Source=LCSServerSQL2005Server;Initial Catalog=RADdb;User ID=user1;Password=pw1”)

Here Data source is the server you are connected to and it can be found by navigating to My Computer -> properties-> Computer Name. Initial catalog is the Database name and User ID, password are the login details to access the sql database if you used any.

Here is the sample code to open the connection.

Try

CN.Open()

If CN.State = ConnectionState.Open Then

MsgBox(“Workstation ” & CN.WorkstationId & ” connected to database ” & CN.Database & ” on the ” & CN.DataSource & ” server”)

End If

Catch ex As Exception

MsgBox(“FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR” & vbCrLf & ex.Message)

End Try

More details can be found by following links.

Update Data using Windows Form and .NET Data Sets

ADO.NET for SQL Servers

Regards

ShaneW

Related Questions