Monday, July 28, 2008

SqlDataSource ConnectionString Dumb Issue

Today I resolved an odd issue I was having with a specific page in a web application I developed.
Although the error message seemed to point to a Named Pipe configuration issue with the remote SQL Server, I just could not get my mind around this one until duh! the connection string for the Page SqlDataSource was different from my dynamic connection strings.

Essentially, I've been using dynamic connection strings for ages. Something I developped a few years back that allows be to store all my SQL server connection strings in my web.config file and the application picks the one that is relevant depending which environment (Local, Dev, Staging or Prod) the web browser is calling.

Now, since the advent of GridViews and the likes, I started developping sections of pages using SqlDataSources... obviously pointing to my local SQL server.

Since the server does exist, I can't really think of a smart error handling routine so as part of my InitPage() method, I reset the SqlDataSource.ConnectionString to the value for my dynamic strings and voilà. Simple solution to a rather obscure simple problem.