Configuring SQL Server Express 2005 - The Connection String
(Page 5 of 5 )
You may come from an ASP background, where you're used to stuffing the connection string into an application level variable, and retrieving it each time you need to access the database. Well you can do that with .Net as well. You can use the web.config file, and write application level variables in an XML format.
In ASP.Net 1, the easiest way was to stuff the string into the appSettings section of the web.config. Now with ASP.Net 2.0, Microsoft has realized that one of if not the most commong thing going in there is a connection string, so they went ahead and created a custom section. This is conspicuously called 'connectionStrings', and you can add a key as you would any other section. A connection string key takes three parameters: connectionString, name, and providerName.
You can use this new feature, or the plain old appSettings. Whichever you choose, the connection string will look like this:
Server=(local)\SQLEXPRESS;
User ID=[userName];
password=[password];
Database=[databaseName];
Persist Security Info=True
Conclusion
The new SQL Server 2005 Express is truly a great tool for developers. I think Microsoft has done it something of an injustice by hailing it as a tool for 'hobbyists and amateurs'. It's fast, lightweight, and very tightly integrated with the .Net 2.0 framework. Once Microsoft releases a GUI administration tool for it, life will be far simpler. But until that time, I hope you are spared many hours of frustration by using the methods described in this article!
By the way, if you would like more information on the SQL Server System Stored Procedures, visit the documentation in MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_00_519s.asp
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |