|
 |
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 .
|
 |
|
|
 |

December 2nd, 2003, 03:17 PM
|
Registered User
|
|
Join Date: Dec 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|

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
|
|
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
|

December 2nd, 2003, 03:37 PM
|
Registered User
|
|
Join Date: Dec 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

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
|
|
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
|

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
|
|
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
|

February 21st, 2014, 10:22 AM
|
Registered User
|
|
Join Date: Feb 2014
Location: india
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |