• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

vb.net reading SQL Server table error

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:


Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form

#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

        Try
            mSqlConnection.Open()
        Catch
            MessageBox.Show(Err.Description)
        End Try

        mDataReader = mSqlCommand.ExecuteReader
        mDataReader.Read()
        MessageBox.Show("Name:  " & mDataReader("au_fname") & " " & mDataReader("au_lname"))

        mDataReader.Close()
        mSqlConnection.Close()
    End Sub

    Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
        Close()
    End Sub

End Class


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.
0
EYoung
Asked:
EYoung
1 Solution
 
EYoungAuthor Commented:
I solved the problem.  The following line:

Dim mSqlConnection As New SqlConnection("initial catalog=SV03.pubs;data source=authors;")

should include the "Integrated Security=SSPI" property and read as follows:

Dim mSqlConnection As SqlConnection = New SqlConnection("Data Source=SV03;Integrated Security=SSPI;Initial Catalog=pubs; ")

Thanks anyway.  I will be asking Community Services to delete this question.
0
 
moduloCommented:
PAQ'd and points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now