Geeks With Blogs
Fred Sobel blog

Trying to figure out the best way to connect to SQl Server express for VS2005 Web development is quite interesting.  You may be able to connect from vs2005 and the new SQL Server Management studio but when it comes time to run your aspx page against a connection you need to do a little extra work.


First thing is security.  If you are using integrated security the ASPNET account needs access to your database.  I found there is more than one way to do this which adds to the confusion.


Option 1)  Attach the mdf file to your running instance of sql server express.  Add the local ASPNET Login under Security for SQLExpress and then add then again as a User under security for your database instance.  Be sure to grant the User enough access.


Then you can connect using something like this:




Integrated Security=SSPI;


Option 2) I later leraned the DB does not need to be explicitly attached but can be refenced using AttachDBFileName=<path_to_mdf>


Data Source=.\SQLEXPRESS;


Integrated Security=True;

User Instance=True;


The problem here is security.  When the MDF is access on the fly like this the ASPNET account must be given access to the MDF (and log) file using Windows XP Secrity.


The question for me now is will this work at my hosting provider?

Posted on Monday, October 23, 2006 8:18 PM | Back to top

Comments on this post: Connecting to SQL Server Express

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Fred Sobel | Powered by: