Connection to SQL server

G

Guest

Hi all,

I'm trying to connect to an SQL database from my vb.net form, but getting an
error message. The code I used is the following:

Private Sub ConnectSQL_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ConnectSQL.Click
Dim myConnection As SqlClient.SqlConnection
myConnection.ConnectionString = "Persist Security
Info=true;Integrated Security=false;User
ID=sa;Password=xxxxx;database=yyy;server=zzzzz\mmmmm"
myConnection.Open()
End Sub

What am I missing?
 
P

Paul Clement

¤ Hi all,
¤
¤ I'm trying to connect to an SQL database from my vb.net form, but getting an
¤ error message. The code I used is the following:
¤
¤ Private Sub ConnectSQL_Click(ByVal sender As Object, ByVal e As
¤ System.EventArgs) Handles ConnectSQL.Click
¤ Dim myConnection As SqlClient.SqlConnection
¤ myConnection.ConnectionString = "Persist Security
¤ Info=true;Integrated Security=false;User
¤ ID=sa;Password=xxxxx;database=yyy;server=zzzzz\mmmmm"
¤ myConnection.Open()
¤ End Sub
¤
¤ What am I missing?

A data source?

See if the following examples help:

http://www.able-consulting.com/dotnet/adonet/Data_Providers.htm#SQLClientManagedProvider
http://www.connectionstrings.com (SqlConnection (.NET))


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
G

Guest

Thanks for your reply.
Is the data source in your example (data source=local) equivalent to the
server name provided in the connection string of my code
(server=zzzzz\mmmmm)? If yes, this shouldn't be the issue. If no, what do you
mean by data source?

Thank you
 
C

C-Services Holland b.v.

TS said:
Hi all,

I'm trying to connect to an SQL database from my vb.net form, but getting an
error message. The code I used is the following:

Private Sub ConnectSQL_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ConnectSQL.Click
Dim myConnection As SqlClient.SqlConnection
myConnection.ConnectionString = "Persist Security
Info=true;Integrated Security=false;User
ID=sa;Password=xxxxx;database=yyy;server=zzzzz\mmmmm"
myConnection.Open()
End Sub

What am I missing?

Maybe this:
Dim myConnection As New SqlClient.SqlConnection()
 
P

Paul Clement

¤ Thanks for your reply.
¤ Is the data source in your example (data source=local) equivalent to the
¤ server name provided in the connection string of my code
¤ (server=zzzzz\mmmmm)? If yes, this shouldn't be the issue. If no, what do you
¤ mean by data source?

I didn't see the "server" argument the first time I looked at the connection string. I don't see any
problem with the syntax.

What is the error you are getting?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
J

Jim Hughes

You need an instance of the SqlConnection object.

Dim myConnection As SqlClient.SqlConnection = new SqlClient.SqlConnection
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top