View Single Post
  #1 (permalink)  
Old August 12th, 2005, 09:59 PM
4-elements 4-elements is offline
Registered User
Join Date: Aug 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql error with

hello i am working on the project in chapter 16 page 638 of the book Beginning VB.NET 2nd edition, and i am getting this error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in

Additional information: System error.

the line...


is highlighted.

i'm trying to connect to the sql server on a box running win 2000 server and i'm running on a win xp box. the wierd thing is that i can navigate to the database through my network places (so i do have connectivity), but i can't get to it through

here's my code...

'Import Data and SqlClient namespaces...
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim myConnection As SqlConnection = New _
        SqlConnection("server=(\\G5-media-server\SQLServer 2000\MSSQL\Data);database=pubs;uid=administrator;p wd=")

    Dim myDataAdapter As New SqlDataAdapter
    Dim myDataSet As DataSet = New DataSet

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents grdAuthorTitles As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.grdAuthorTitles = New System.Windows.Forms.DataGrid
        CType(Me.grdAuthorTitles, System.ComponentModel.ISupportInitialize).BeginIni t()
        Me.grdAuthorTitles.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.grdAuthorTitles.DataMember = ""
        Me.grdAuthorTitles.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.grdAuthorTitles.Location = New System.Drawing.Point(5, 5)
        Me.grdAuthorTitles.Name = "grdAuthorTitles"
        Me.grdAuthorTitles.Size = New System.Drawing.Size(584, 192)
        Me.grdAuthorTitles.TabIndex = 0
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(592, 196)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
        Me.Text = "Bound Dataset"
        CType(Me.grdAuthorTitles, System.ComponentModel.ISupportInitialize).EndInit( )

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the SelectCommand properties...
        myDataAdapter.SelectCommand = New SqlCommand
        myDataAdapter.SelectCommand.Connection = myconnection
        myDataAdapter.SelectCommand.CommandText = _
            "SELECT au_lname, au_fname, title, price " & _
            "FROM authors " & _
            "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
            "JOIN titles ON titleauthor.title_id = titles.title_id " & _
            "ORDER by au_lname, au_fname"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text

        'Open the database connection...

        'Now execute teh command...

        'Fill the Dataset object with data...
        myDataAdapter.Fill(myDataSet, "authors")

        'Close the database connection...

        'Set the DataGrid properties to bind it to our data...
        grdAuthorTitles.DataSource = myDataSet
        grdAuthorTitles.DataMember = "authors"

    End Sub

End Class


Reply With Quote