A
Andrew
Hi
I am trying to connect to an instance of SQL Server 2005 (Express)
from a project in VB2005.
Forgive my ignorance - I know very little of SQL 2005 security (and
not that much more of VB2005!) but I wonder if anyone can help.
I am getting the message "Invalid attempt to read when no data is
present" every time I try to use a Data Reader object. The code that
accesses the Data reader is as follows:
Sub TestConnection
Using cnn As New
SqlConnection(My.Settings.SQLConnectionString)
Using cmd As New SqlCommand( _
"Select CategoryID, CategoryName FROM Categories " &
_
"ORDER BY CategoryName", cnn)
cnn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader
MsgBox(dr(0)) ' This is just a test for accessing
the data
End Using
End Using
End Using
End Sub
The SQL connection string is listed in app.config as follows:
<connectionStrings>
<add name="AccessingData.My.MySettings.SQLConnectionString"
connectionString="Data Source=.\SQLExpress;Initial
Catalog=Northwind; Integrated Security=SSPI" />
</connectionStrings>
SQL server is set to use SQL Server and Windows Authentication mode.
I know that the table exists, and that the field names etc are spelt
correctly, and that there is data in the table. Yet the error I get
implies a lack of data, rather than an error in the security info, or
connection string etc.
Can anyone help? Please??!
Thanks a lot
Andrew
I am trying to connect to an instance of SQL Server 2005 (Express)
from a project in VB2005.
Forgive my ignorance - I know very little of SQL 2005 security (and
not that much more of VB2005!) but I wonder if anyone can help.
I am getting the message "Invalid attempt to read when no data is
present" every time I try to use a Data Reader object. The code that
accesses the Data reader is as follows:
Sub TestConnection
Using cnn As New
SqlConnection(My.Settings.SQLConnectionString)
Using cmd As New SqlCommand( _
"Select CategoryID, CategoryName FROM Categories " &
_
"ORDER BY CategoryName", cnn)
cnn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader
MsgBox(dr(0)) ' This is just a test for accessing
the data
End Using
End Using
End Using
End Sub
The SQL connection string is listed in app.config as follows:
<connectionStrings>
<add name="AccessingData.My.MySettings.SQLConnectionString"
connectionString="Data Source=.\SQLExpress;Initial
Catalog=Northwind; Integrated Security=SSPI" />
</connectionStrings>
SQL server is set to use SQL Server and Windows Authentication mode.
I know that the table exists, and that the field names etc are spelt
correctly, and that there is data in the table. Yet the error I get
implies a lack of data, rather than an error in the security info, or
connection string etc.
Can anyone help? Please??!
Thanks a lot
Andrew