Please Explore this
Image
As You Can See From Listing 11-13 Authors Expose the connection string for the regular SqlServer(not Express).
You Can probably receive errors because of the TWO main problems.
First: The connection String(aspx.page) Using "sa" for login, and "Password" for Password.
This means that this connection string wil work ONLY With The Full-Sql2005Server(Not-Express)
Second: Your OpenWEbConfiguration Method Doesn't see Your Project, because You simply using a different name I Use Listing 17-2 for example. so for me it goes like this:("/Listing17-2")
********************************
// Add the new connection string to the web.config
Configuration config = System.Web.Configuration.WebConfigurationManager.O penWebConfiguration("/YourProjectNameHere");
config.ConnectionStrings.ConnectionStrings.Add(con n);
config.Save();
In General*** If you don't have a full-version Sql2005Server
You Will need to change the connection string in the aspx.page to the SqlExpress connection String.
**Another words(Let's say) SqlExpress is using another autentication type. No need in Sa username and password pass.
Thats why you need to change the main conn\string to sqlExpress Con\string if you using SqlExpress2005
Here what you can do without guessing what the real connectionString must be.
*Try to create Some new SqlDataSource control, and bind it to the SqlExpress2005Server.
*After binding it to the server, it will automaticaly create a conn\string for you in the web.config file.[no need to guess!]
*Then you can explore your conn\string presented in the web.config file.
*After doing this simply go back to your aspx.page and change the connectionString according to your new Connection String in the web.config file.
You will probably understand which changes to add to the connection string in your aspx.page.
You will add an
MachineKey/SQLEXPRESS..se the rest of the code in Web.config. and so on...
**Basically You will change only the ConnectionString Line.
and the conn.Name + connProviderName will still the same.
I think you get the idea of this.
Refer to the Image above and explore the SqlExpressConnection String.
The truth is, the SqlExpress and SqlServer2005 conn\strings looks pretty much the same. you will see from the image wich lines of code to change to flip it to Express compatible. this is very easy to do.
Refer to Image, for mor clear understanding. It's not that hard I promise :)
*Finally After running the code, you will receive Blank Html Page.
Simply close this Page, and go back to your VisualStudio. this
DialogWindow will PopUp. Simply click YesToAll Button. and go to your Web.config file.the new created connectionString will appear in the web.config file.
Explore the Image carefully, this is very easy to FIX. you will understand how this works in a second. I had tested Listing 11-13 in both SqlExpress2005Server and the full-Sql2005Server
Works fine in both.
I hope this explanation will help to solve your problem.
Take care!