Link to home
Create AccountLog in
Avatar of prederso
predersoFlag for Sweden

asked on

Connection from VB6 to .NET

I have just started looking into VB.NET but are having problems making a database connection. The connection I used in VB6 looked like this:

Set Cn = CreateObject("ADODB.Connection")
Cn.Open("driver={SQL Server};Server=serv1;network=ps;uid=ts;pwd=ts;database=telesales")

What would that connection looke like in .NET??
Avatar of Anil_Poonia
Anil_Poonia

hi  prederso

Use This:

   Dim connString As String
    Dim conn As OleDb.OleDbConnection
conn=new OleDb.OleDbConnection

        connString = "Provider=sqloledb;Data Source=localhost;User Id=sa;Initial Catalog=Pubs;"
        conn = New OleDbConnection
        conn.ConnectionString = connString
        conn.Open()



Regards

Anil Poonia
Avatar of prederso

ASKER

But can I use Data Source = localhost when i need to access the database on a network?
Hi prederso,

Just drag a sqlconnection from the toolbox onto your form and fill in the wizard. You can than look in the windows generated code if you are interested in the complete code.

ASKER CERTIFIED SOLUTION
Avatar of Anil_Poonia
Anil_Poonia

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
here is a great site, I use it all the time.

http://www.connectionstrings.com/