Thursday, February 16, 2012

Am I missing something when trying to connect via ASP.NET 2.0?

I am at my wit's end trying to set up a simple test to retrieve some records from with ASP.NET and C#. I'm using the Express Edition on my development laptop. Whenever I try to run my application, I get the following error:

ERROR: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I have researched this problem, and done everything I can find online to fix it but no avail. I have gone to SQL Server Configuration Manager and enabled Named Pipes and TCP/IP. I have stopped and restarted the server. Local and Remote connections (Both TCP/IP and Named Pipes) are enabled in the Surface Area Configuration. I added it to the Exceptions list of the Windows firewall. And yet nothing works. I can connect to it fine with Management Studio Express, but I am totally unable to connect to the database from within my code. I've spent probably about two weeks wracking my brain trying to figure this out; does anybody know what might be causing the problem and what could fix it?what does your connection string look like.|||"Server=ORPHEUS;Database=TestDB;User ID=sa;Password=mypass;Trusted_connection=False"

I've also tried specifyinig the instance of SQL Server (e.g. Server=ORPHEUS\SQLExpress) but that does not work either.
|||

If you're trying to connect to an instance name, then i'm pretty sure you have to specify it in your connection string.

Have you tried using the examples in the docs, like this one? http://msdn2.microsoft.com/en-us/library/ms247257.aspx

|||Well what do you know... turns out I wasn't specifying it in the right format.. I should have had it was "Database=ORPHEUS\\SQLEXPRESS".

Thanks a ton! Sometimes its the most obvious things that you end up missing...

No comments:

Post a Comment