vb.net reading SQL Server table error
Posted on 2003-02-25
Basics: VB.Net, Windows 2000, SQL Server 7.0
I am new to VB.net and am trying to do a simple read from the SQL Server table called pubs in the SQL Server Group called SV03. However, I am getting the following error when I hit the following statement "mSqlConnection.Open()" in my code.
"SQL Server does not exist or access denied."
Below is my code:
Public Class Form1
#Region " Windows Form Designer generated code "
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
Dim mSqlConnection As New SqlConnection("initial catalog=SV03.pubs;data source=authors;")
Dim mSqlCommand As New SqlCommand("Select * from Authors", mSqlConnection)
Dim mDataReader As SqlDataReader
mDataReader = mSqlCommand.ExecuteReader
MessageBox.Show("Name: " & mDataReader("au_fname") & " " & mDataReader("au_lname"))
Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
The form just has two buttons on it. A Start button and a Stop button. Clicking the Start should open the connection, read the first record and display the first and last name of the author. It is just that simple, nothing more. I just want to see how to read a record from a SQL Server table.
The table is in the "pubs" database in the SQL Server Group called "SV03". The database uses Windows Authentication.
Thank you for any help.