Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2003, 03:17 PM
BB BB is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default An unhandled exception of type 'System.Data.SqlCli

Can someone give me some ideas on how to solve this. I am working on the example on page 638 in the book. The only differences I made was I used one of my databases out on the server and a different query. I get this error right at myConnection.Open.

 See code below:

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim myConnection As SqlConnection = New _
SqlConnection("server=Servername; database=databasename; uid=UUU; pwd=PPP")


    Dim myDataAdapter As New SqlDataAdapter()
    Dim mydataset As DataSet = New DataSet()

    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 col1, col2, col3, col4" & _
            "from table1 order by col1"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text


        'Open the database connection...
        myConnection.Open()

        'Now execute the command...
        'myDataAdapter.SelectCommand.ExecuteNonQuery()

        'Fill the DataSet object with data...
        myDataAdapter.Fill(mydataset, "Test")

        'Close the database connection...
        myConnection.Close()

        'set the datagrid properties to bind it to our data...
        grdAuthorTitles.DataSource = mydataset
        grdAuthorTitles.DataMember = "Test"

    End Sub
End Class


Any thoughts? Thanks!


 
Old December 2nd, 2003, 03:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

What error? It was truncated in the subject.
What book?

I think I know what your issue is anyway:

myDataAdapter.SelectCommand.CommandText = _
            "Select col1, col2, col3, col4" & _
            "from table1 order by col1"

There is a space missing between col4 & from. Your command would be:
"Select col1, col2, col3, col4from table1 order by col1"

BTW:
It is faster in VB.NET to use a string builder rather than the &.


John R Lick
JohnRLick@hotmail.com
 
Old December 2nd, 2003, 03:37 PM
BB BB is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the full error

"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error."

I took away the space, but still get the error. I will look in to trying the string builder.

Thanks

 
Old December 2nd, 2003, 05:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

Do you mean that you added a space? I was telling you that there should have been a space where there wasn't one.

Another thing you may want to try, is having the code print out the SQL statement that you want to try. Copy & Paste the SQL statement into a Query program (SQL Query Analyzer for MS-SQL). And see what error you get. Resolve it there, then fix your VB to build the correct statement.

John R Lick
JohnRLick@hotmail.com
 
Old December 4th, 2003, 05:19 PM
Authorized User
 
Join Date: Oct 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

BB,

I'm not familiar with the example in the book but my connection string uses this for id and password parameters not uid or pwd
Code:
user id=XXXXX; password=XXXXX
Also enclose the conn.open() with a try block and have a printline or msgbox show you the ex.message or ex.stacktrace

Code:
Try
   SqlConn.Open()
   SqlDataAdapter.Fill(ds, "Data")
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   SqlConn.Close()
End Try
Thanks,
Risu
 
Old February 21st, 2014, 10:22 AM
Registered User
 
Join Date: Feb 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to chaudharis57
Angry An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in Syste

Quote:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim CMD As SqlCommand
If con.State = ConnectionState.Open Then con.Close()
con.Open()

query = "select * from USERLOGIN where USERID='" & txtUsername.Text & "'and UPASSWORD='" & txtPasswd.Text & "'"

da = New SqlDataAdapter(query, con)
ds = New DataSet
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
'valid user
USERNAME = txtUsername.Text

USERTYPE = ds.Tables(0).Rows(0).Item(3)
logintime = Now
DELETETIME()

If con.State = ConnectionState.Open Then con.Close()
con.Open()

'query = "UPDATE USERLOG SET ULOGDATE='" & Today & "',ULOGINTIME='" & Now & "' WHERE USERID='" & USERNAME & "'"
query = "INSERT INTO USERLOG VALUES('" & txtUsername.Text & "','" & Today & "','" & Now.TimeOfDay.ToString & "')"

CMD = New SqlCommand(query, con)
CMD.ExecuteNonQuery()


con.Open()


con.Close()


frmMDIMain.Show()
Me.Hide()


Else
MsgBox("INVALID LOGIN")

End If

txtUsername.Text = ""
txtPasswd.Text = ""
txtUsername.Focus()


End Sub
this my code.

when I run It

pop up window shows
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System. Data.dll

Additional information: Cannot open database "MULTIPLEX" requested by the log in. The log in failed.
Log in failed for user 'magicbox\Administrator'.

this message.

how can I solved it?





Similar Threads
Thread Thread Starter Forum Replies Last Post
unhandled exception dipakp ASP.NET 2.0 Professional 1 July 6th, 2007 02:16 PM
An unhandled exception of type 'System.Data.OleDb. Harvey_swift VB Databases Basics 1 May 30th, 2006 12:57 PM
unhandled exception of type 'System.Net.WebExcepti booksnore2 C# 0 June 26th, 2004 07:26 AM
Unhandled Exception stu9820 ASP.NET 1.0 and 1.1 Basics 11 January 14th, 2004 05:55 PM
Unhandled Exception: mbarrett C# 3 August 1st, 2003 05:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.