473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sqlDataAdapter Error

I have the following code attached to the click event of a button. It fails
on the line "da.Fill (ds, "Results") The error is below the code. Any
suggestions would be greatly appreciated. Thanks.

Dim cmd As SqlCommand = SqlConnection1.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = txtQuery.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "Results")
dgResults.DataSource = ds
dgResults.DataMember = "Results"

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

Additional information: System error.

--
Joe Micheli CPA, CMA, CFM, CPIM
Aug 11 '05 #1
2 2653
There are a ton of things that can be wrong. First, check that your
connection string is good. YOu may want to open the connection manually
(just for testing) before you call fill to verify that your connection
string is good. So make sure that you have permissions to access the db, the
server name is right etc etc. This is a very likely culprit. Next, I'd
verify that txtQuery.Text will parse.

Also, I'd try catch the .Fill statement (and try catching Connection.Open is
a good idea in many cases since a lot can go wrong with opening a db
connection that's out of your immediate control).
(I'm coding the VB.nET without the ide so I may have a syntax error or two -
but you should get the idea)
Try
da.Fill(ds, "Results")
Catch ex as SqlException
Dim message as New StringBuilder
For Each err as SqlError in ex.Errors
message.Append(err.Message + ControlChars.CrLf)
Next
Debug.Assert(false, message.ToString)
End Try

This will loop through the errors collection and may point you in the right
direction. Let me know if this doesn't fix it.
"joseph micheli" <jo***********@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
I have the following code attached to the click event of a button. It
fails
on the line "da.Fill (ds, "Results") The error is below the code. Any
suggestions would be greatly appreciated. Thanks.

Dim cmd As SqlCommand = SqlConnection1.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = txtQuery.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "Results")
dgResults.DataSource = ds
dgResults.DataMember = "Results"

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

Additional information: System error.

--
Joe Micheli CPA, CMA, CFM, CPIM

Aug 11 '05 #2
Thanks for the tip. The Try...Catch revealed that the login was failing on
"sa". I changed the server connection to use windows user login and the
problem was resolved.
--
Joe Micheli CPA, CMA, CFM, CPIM
"W.G. Ryan MVP" wrote:
There are a ton of things that can be wrong. First, check that your
connection string is good. YOu may want to open the connection manually
(just for testing) before you call fill to verify that your connection
string is good. So make sure that you have permissions to access the db, the
server name is right etc etc. This is a very likely culprit. Next, I'd
verify that txtQuery.Text will parse.

Also, I'd try catch the .Fill statement (and try catching Connection.Open is
a good idea in many cases since a lot can go wrong with opening a db
connection that's out of your immediate control).
(I'm coding the VB.nET without the ide so I may have a syntax error or two -
but you should get the idea)
Try
da.Fill(ds, "Results")
Catch ex as SqlException
Dim message as New StringBuilder
For Each err as SqlError in ex.Errors
message.Append(err.Message + ControlChars.CrLf)
Next
Debug.Assert(false, message.ToString)
End Try

This will loop through the errors collection and may point you in the right
direction. Let me know if this doesn't fix it.
"joseph micheli" <jo***********@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
I have the following code attached to the click event of a button. It
fails
on the line "da.Fill (ds, "Results") The error is below the code. Any
suggestions would be greatly appreciated. Thanks.

Dim cmd As SqlCommand = SqlConnection1.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = txtQuery.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "Results")
dgResults.DataSource = ds
dgResults.DataMember = "Results"

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

Additional information: System error.

--
Joe Micheli CPA, CMA, CFM, CPIM


Aug 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JEP | last post by:
I lifted the following code directly from MSDN examples. However, the update command fails against my Northwind/SQL Server database. The code is: Private Sub cmdStart_Click(ByVal sender As...
2
by: DraguVaso | last post by:
Hi, I have a DataGrid bound to an sqlDataAdapter. When I do a SqlDataAdapter.Update, on 1 row I got a red dot with a whie exclamation mark in it, to show me there is an error, and the changes...
3
by: W Akthar | last post by:
I am trying to use SqlDataAdapter to execute a Stored Procedure. The Stored Procedure is as follows CREATE Procedure SP_GetAddressesFromContactID @ID int AS SELECT b.StreetAddress1,
6
by: Jerry Higgins | last post by:
I added a SqlDataAdapter to a web form, created a data connection, and generated a dataset. I then connected it to a DataGrid control. When I do this using the SqlServer database on my machine...
6
by: M | last post by:
Hi, Does SqlDataAdapter always close the connection (assuming connection was closed before calling Fill()), even if an exception occurs while calling Fill()? Example: try {...
4
by: HS1 | last post by:
Hello. I declare a SqlDataAdapter in a FormLoad as below. However, there is error claimed that the SqlDataAdapter is not defined. Could you please tell me what to do ------------------ ...
3
by: joseph micheli | last post by:
I have the following code attached to the click event of a button. It fails on the line "da.Fill (ds, "Results") The error is below the code. Any suggestions would be greatly appreciated. ...
1
by: archana | last post by:
Hi all I ma having problem in sqldataadapter. In my sql database i have one table containing column name as 'Name and address'. Here 'and' is reserved word which i am using in column name. In...
1
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.