Can anyone tell me what is wrong with this code :
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Orders; User id=sa");
SqlCommand comm = new SqlCommand("Select * from cust", con);
con.Open();
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
Response.Write(dr.GetSqlValue(0).ToString());
Response.Write(dr.GetSqlValue(1).ToString());
}
Whenever i try to execute this code, it displays the following error:
Server Error in '/Orders' Application.
Unknown error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Unknown error.
Source Error:
Line 44:
Line 45: SqlCommand comm = new SqlCommand("Select * from cust", con);
Line 46: con.Open();
Line 47: SqlDataReader dr = comm.ExecuteReader();
Line 48:
Source File: c:\inetpub\wwwroot\orders\customerdetailsform.aspx.cs Line: 46
Stack Trace:
[SqlException: Unknown error.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Orders.CustomerDetailsForm.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\orders\customerdetailsform.aspx.cs:46
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Can anyone give me a solution for this.
Thanks,
Shailaja.

ExecuteReader Error
Saresh Naroji
It sounds like your connection string is the problem. Try this out:
This will show you the connection string that you need to use.
Note: You will need to remove the section that contains Provider= since ADO.NET already knows to use SQL Server since you are using the SQL Server data objects.
PS - Are you using SQL Server
carsc
Hope this helps.
DHardy
This code also doesn't work.
can u pls suggest me someother code.
Thanks,
Shailaja.
Abbyy
Check out the link
http://www.intellectualbrains.com/DiscView.aspx mid=153&forum_id=3&
Allan Braun
I'm using SQL server as backend.
Can u explain the previous solution in detail.
how to set the connection from a notepad.
Thanks,
Shailaja.
Ben Waldron
Hello,
Thanks for your reply.
But after making the specified changes also, the code doesn't work.
can u pls suggest some other code.
I'm new to ASP.net, so finding a bit tough to sort it out.
Thanks,
Shailaja.