Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect a SQL Server DB to VB.net?

Status
Not open for further replies.

dzisaacs

Programmer
Dec 12, 2002
53
PA
I'm trying to connect to a SQL Server DB over a LAN... I would like to know how to do this, because i've searched a lot but haven't found too much help...If you know the code of how to do this it would be even better. THANK YOU
 
Option Strict Off
Option Explicit On
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
Dim DBconnect As New SqlConnection
Dim DBadp As New SqlDataAdapter
Dim dbcom As New SqlCommand
Dim A As New DataSet
Dim B As New DataSet


Load event of form

If DBconnect.State = ConnectionState.Closed Then
DBconnect.ConnectionString = "Provider=sqloledb;DRIVER=SQLServer;
SERVER=SQLservername;UID=xxxx;PWD=xxxxxxxx;DATABASE=YourDatabasename"
DBconnect.Open()
End If

dbcom.Connection = DBconnect
DBadp.SelectCommand = dbcom
dbcom.CommandText = "select * from MyTable order by id"
DBadp.Fill(A, "mytable")


Hope this helps,

FoxT
 
try this code if you want use windows authentication
remember that sspi doesnt work very well with tcp/ip and windows xp,so switch to named pipes.

Code:
            DBconnect.ConnectionString = "workstation id=" & SQLservername & ";integrated security=SSPI;packet size=4096;data source=" & SQLservername & ";persist security info=False;initial catalog=" & Databasename

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top