This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C3E0FC.F1C1DBA0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello I am trying to access my data using some of the examples on the VB =
Resource CD to learn about VB.net. I have used the following code:

Public Sub InsertRow(ByVal myConnectionString As String)
MyConnectionString =3D "database=3DNorthwind;Server=3Dlocalhost"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As =
System.EventArgs) Handles Button2.Click
Dim myConnection As New SqlConnection
Dim myInsertQuery As String =3D "INSERT INTO Customers (CustomerID, =
CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection =3D myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub 'SelectSqlClientSrvRows


When I click f5 and run the app, I get no compile errors. When I click =
on the button, however and attempt to access the server, I get the =
following error:

An unhandled exception of type 'System.InvalidOperationException' =
occurred in system.data.dll

Additional information: The ConnectionString property has not been =
initialized.

Additional information is as follows:
1. I have Visual Studio.net installed with MSDE on my computer. In my =
server explorer I have the following items showing.=20
SQL Servers ---GARYLAP\INSTANCE--------

2. Under the GARYLAP\INSTANCE I have the following databases:
Master
Model
MSDB
Northwind

I have modified the connection string until I finally gave up. I tried =
server =3Dgarylap and garylap\instance but to no avail. Any help would =
be greatly appreciated. =20

Thanks,

Gary


------=_NextPart_000_0008_01C3E0FC.F1C1DBA0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1276" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hello I am trying to access my data =
using some of=20
the examples on the VB Resource CD to learn about VB.net.&nbsp; I have =
used the=20
following code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Public Sub InsertRow(ByVal =
myConnectionString As=20
String)<BR>MyConnectionString =3D =
"database=3DNorthwind;Server=3Dlocalhost"<BR>End=20
Sub<BR>Private Sub Button2_Click(ByVal sender As System.Object, ByVal e =
As=20
System.EventArgs) Handles Button2.Click<BR>Dim myConnection As New=20
SqlConnection<BR>Dim myInsertQuery As String =3D "INSERT INTO Customers=20
(CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')"<BR>Dim =
myCommand=20
As New SqlCommand(myInsertQuery)<BR>myCommand.Connection =3D=20
myConnection<BR>myConnection.Open()<BR>myCommand.ExecuteNonQuery()<BR>myC=
ommand.Connection.Close()<BR>End=20
Sub 'SelectSqlClientSrvRows</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>When I click f5 and run the app, I get =
no compile=20
errors.&nbsp; When I click on the button, however and attempt to access =
the=20
server, I get the following error:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>An unhandled exception of type=20
'System.InvalidOperationException' occurred in =
system.data.dll</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Additional information: The =
ConnectionString=20
property has not been initialized.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Additional information is as =
follows:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>1.&nbsp;&nbsp;&nbsp; I have Visual =
Studio.net=20
installed with MSDE on my computer.&nbsp;In my server explorer I have =
the=20
following items showing. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>SQL Servers&nbsp;=20
---GARYLAP\INSTANCE--------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2.&nbsp;&nbsp;&nbsp; Under the=20
GARYLAP\INSTANCE&nbsp; I have the following databases:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Master</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Model</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>MSDB</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Northwind</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have modified the connection string =
until I=20
finally gave up.&nbsp; I tried server =3Dgarylap and garylap\instance =
but to no=20
avail.&nbsp; Any help would be greatly appreciated.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Gary</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0008_01C3E0FC.F1C1DBA0--

RE: Beginner's Question--accessing database server by HussAb

HussAb
Thu Jan 22 20:39:17 CST 2004

Gary,

In your code, you didn't set the connectionstring for the connection object
unless you didn't include it all. You have InsertRow function that takes
one parameter but it does nothing. Propably what you need to do is:

- Remove InsertRow function since it is redundant.
- Modify Button2 click event code to:

Dim ConStr as String =
"Server=yourMSDEinstancename;database=Northwind;Integrated security=SSPI"
Dim myConnection As New SqlConnection(ConStr)
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID,
CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub 'SelectSqlClientSrvRows

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.


RE: Beginner's Question--accessing database server by anonymous

anonymous
Tue Feb 24 23:06:09 CST 2004

You may also need to change the server name from "localhost" to "(local)" or to the IP address "127.0.0.1". Localhost may not work because of name resolution issues unrelated to your code issues. I had that problem.