Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 2nd, 2003, 03:17 PM
BB BB is offline
Registered User
 
Join Date: Dec 2003
Location: , , .
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!


Reply With Quote
  #2 (permalink)  
Old December 2nd, 2003, 03:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sparks, NV, USA.
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
Reply With Quote
  #3 (permalink)  
Old December 2nd, 2003, 03:37 PM
BB BB is offline
Registered User
 
Join Date: Dec 2003
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old December 2nd, 2003, 05:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sparks, NV, USA.
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
Reply With Quote
  #5 (permalink)  
Old December 4th, 2003, 05:19 PM
Authorized User
 
Join Date: Oct 2003
Location: Bohemia, NY, USA.
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
Reply With Quote
  #6 (permalink)  
Old February 21st, 2014, 10:22 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Location: india
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?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
unhandled exception dipakp ASP.NET 2.0 Professional 1 July 6th, 2007 03:16 PM
An unhandled exception of type 'System.Data.OleDb. Harvey_swift VB Databases Basics 1 May 30th, 2006 01:57 PM
unhandled exception of type 'System.Net.WebExcepti booksnore2 C# 0 June 26th, 2004 08: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 06:25 PM



All times are GMT -4. The time now is 04:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.