Thursday, February 16, 2012

ASP.NET/C# Accessing a SQL DB

Good Morning,

I am wondering if anyone can help me/ Currently I have created an ASP.NET webform. Usingt the VS.NET C# IDE I have put a SQL connection and DataAdapter on the webform. I have then created a dataset which should hold the contents of a table on a SQL server db.

However when i run the page which just tries to fill the dataset i get the error below. I am running the page via IIS on WinXP Pro SP1 system and SQL Server is located on a Win2003 Svr.

Can anyone help?

Thanks & Regards,

Alan

Server Error in '/Quiz' Application.
------------------------

SQL Server does not exist or access denied.
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: SQL Server does not exist or access denied.

Source Error:

Line 38: // Put user code to initialize the page here
Line 39:
Line 40: sqlConsumerDataAdapter.Fill(consumerDS11);
Line 41:

Source File: c:\inetpub\wwwroot\quiz\webform1.aspx.cs Line: 40

Stack Trace:

[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +484
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
Quiz.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\quiz\webform1.aspx.cs:40
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573Check out the items in the Microsoft KB article:

http://support.microsoft.com/?kbid=328306|||Hi Darrell,

Thanks for the reply. I had found that KB on the Knowledge Base and have seen it mentioned in previous postings. Unfortunately it hasnt helped me too much.

Do you have any other suggestions?

The funny thing is I can edit the tables in SQL Server via Visual Studio and the SQL client tools installed on my system. Also if my ASP.NET page runs correctly if it is running via the ASP.NET WebMatrix webserver but produces these errors if its run via IIS.

Any help would be greatly appreciated!

Thanks & Regards,

Al.|||Are you using impersonation and Windows authentication? Also, what does your connection string look like? Thanks.|||I have set the authenication as 'SQL Server and Windows' in Enterprise Manager of SQL Server and I am trying to connect to the server using Intregrated security. Although I have tried used a specific a username & password to access the database. The connection was generated by Visual Studio as I used the forms designer. The connection string is as follows:


//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=MSDEMOWKS2;packet size=4096;user id=sa;integrated security=SSPI;da" +
"ta source=\"shannon-svr\";persist security info=False;initial catalog=CompetencyMC" +
"T";
|||Try removing the "user id=sa;" part. If you are using integrated security, you should not need that. Then make sure you set authentication in your web.config = "Windows". And make sure you set the identity impersonate tag = true.

Then post what happens.|||Thanks for your help Darrell, After a reboot of the server and client system and a little playing around. At the moment I am no longer getting the error above.

I am getting the following error

"Connect Failed:
SQLState: '28000'
SQL Server Error: 18452
[Microsoft][ODBC SQL Driver]Login failed for user null '(null)'. Reason not associated with a trusted SQL Server"

I am setting up, impersonation in ASP.NET using the Knowledge base article: 315159.

Hopefully this willl resolve my problem.|||It should. Once you get to a known error like that, things are usually much easier.

No comments:

Post a Comment