473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Connect to SQL server

TS
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS
Nov 21 '05 #1
8 2861
What error message are you getting? Did you try making the connection in
Server Explorer?

Chris

"TS" <TS@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS

Nov 21 '05 #2
"TS" <TS@discussions.microsoft.com> schrieb:
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\mmm mm"
myConnection.Open()
End Sub


For possible connection strings, see
<URL:http://www.connectionstrings.com/>. What error message are you
getting?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
You need to instantiate your connection as a 'New SQLClient.SQLConnection'.

Dim myConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection

You should use a 'Try Catch' to trap your errors. You would have received
the
error:
'Object reference not set to an instance of an object.'
M. Miller


"TS" <TS@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS

Nov 21 '05 #4
Example:

Dim strConnectionString As String =
"server=(local);database=pubs;Trusted_Connection=y es"

chanmm

"TS" <TS@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS

Nov 21 '05 #5
TS,

Because there are more answers, have a look at the answer from Marc, the
others two can nock at there head when they see what they wrote while it was
so easy. (Not that it is important they both give mostly great answers and I
make those mistakes as well.)

:-)

Cor
Nov 21 '05 #6
TS
Chris,
Thanks for your reply. I coudn't establish the connection from Server
Explorer because I have vb.net standard edition

"Chris, Master of All Things Insignifican" wrote:
What error message are you getting? Did you try making the connection in
Server Explorer?

Chris

"TS" <TS@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS


Nov 21 '05 #7
TS
Marc,
Thanks a lot. I tried the code you suggested and it worked fine.

"Marc Miller" wrote:
You need to instantiate your connection as a 'New SQLClient.SQLConnection'.

Dim myConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection

You should use a 'Try Catch' to trap your errors. You would have received
the
error:
'Object reference not set to an instance of an object.'
M. Miller


"TS" <TS@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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\mmm mm"
myConnection.Open()
End Sub

What am I missing?

--
TS


Nov 21 '05 #8
TS
Thanks for your reply. I tried what Marc suggested and it worked fine.

"Herfried K. Wagner [MVP]" wrote:
"TS" <TS@discussions.microsoft.com> schrieb:
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\mmm mm"
myConnection.Open()
End Sub


For possible connection strings, see
<URL:http://www.connectionstrings.com/>. What error message are you
getting?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jerry Orr | last post by:
We are trying to determine the easiest (and cheapest) way to get connections for about 50 Win2K workstations on our LAN to DB2 on a z/OS server. We could install DB2 Connect Personal Edition on...
4
by: Scott Holland | last post by:
HELP - Need to connect to DB2 database on AIX from NT server. Also AS/400 from NT Server -- I am experienced in ORACLE and a novice at DB2. What tools would be the equivalent of Net*8 or...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
5
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit...
14
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I...
0
by: Clodoaldo Pinto | last post by:
Can't connect to postgresql server php error log message: PHP Warning: pg_connect() : Unable to connect to PostgreSQL server: could not connect to server: Permission denied\n\tIs the server...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
0
by: tamayi | last post by:
I have a problem (like most others posting issues on this forum :) ) I have a remote server running Windows XP SP2, with both SQL Server 2005 Express with Advanced Features and SQL 2000...
7
by: RN1 | last post by:
Is it possible to connect to my local SQL Server 2005 database from a remote web server? If yes, what ConnectionString do I use? Thanks, Ron
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.