Default ASP.NET Web Administration with SQL Server 2005, and a PreserveProperty Control

The ASP.NET 2.0 machine configuration has a pre-defined connection string for providers which points to the default SQLExpress Edition configuration that ships with Visual Studio 2005. As a result, if you never installed the Express edition and use SQL Server 2005, it won't work. To get the expected 'out-of-the-box' functionality of the Web Site Administration Tool , you can change the machine.config. Here's an example from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config:

original:

<runtime/>
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=DataDirectoryaspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>

Adjusted:

<runtime/>
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=.\YOURSQL2005;Initial Catalog=aspnetdb;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>

Update [2006/01/28]:
Responding to this on the asp.net MS newsgroup to someone who was having issues with this with their web hosting company (who it appears already had their default membership database configured in machine.config):

"If the error you receive is still the one about an already attached DB of the same name, how have you modified the web.config file? It needs to have a
<connectionstrings></connectionstrings> section and in that section you need the following tags (in order):
<remove name="LocalSqlServer">
<add name="LocalSqlServer" connectionstring="data source=YourServerandInstance;Integrated Security=SSPI;AttachDBFilename=DataDirectoryYourAppDB.mdf;User Instance=true" providername="System.Data.SqlClient">

Obviously, you'll need to modify the server/instance and mdf values. The key is that ASPNET uses the "LocalSqlServer" connection string to do its authorization, etc.-- "



PreserveProperty Control

MVP buddy Rick Strahl has a created a really interesting control to save other controls' state. This enables you to declare what properties you specifically want, which represents improvement over ViewState and even ControlState. Several developers who looked at Rick's original work, including yours truly, suggested improvements and Rick has incorporated these. I've already backported this to ASP.NET 1.1 and plan to do some more testing on it. I added a Cache option in addition to the HiddenField and SessionVariable Storage options as some testing I did earlier indicated that using Cache to store ViewState-related stuff was the most performant. One thing I really respect about Strahl is that he isn't afraid to put out unfinished ideas and take good feedback from others, and then work these improvements in (along with other good stuff he's discovered in the process). That's the mark of a professional developer!

Comments

Popular posts from this blog

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX

System.Web.Caching.Cache, HttpRuntime.Cache, and IIS Recycles

FIX: Requested Registry Access is not allowed (Visual Studio 2008)