Change connection string at runtime! Is it effect on your application?

Change connection string at runtime! Is it effect on your application?

Old forum URL: forums.lhotka.net/forums/t/6406.aspx


Raghav posted on Thursday, February 12, 2009

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Dear friends

I am using CSLA.NET 3.6 version. I have some issue with connection string.

See my connection string is as mentioned below (before running my application),

Connection string file is MyApp.exe.config

<add name="MyApp" connectionString="Data Source=;Initial Catalog=;User ID=;Password=" providerName="System.Data.SqlClient" />

While logging in I change my connection sting as mentioned below,

<add name="MyApp" connectionString="Data Source=MyServer;Initial Catalog=MyDB;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />

I have changed highlighted words in my connection string file while logging in.

The problem is that application will not take the modified connection string while logging in, but when I run my application next time it takes the modified connection string.

Application takes a connection string from MyApp.exe.config file while loading application. This connection string remains same until unless we close the application.  That means connection string loads only once at a time while loading an application.

We can change connection string in config file while application running, but It will not effect on application.

I want to change my connection string at runtime and it also should effect on application, please help me out!

Thanks

Raghav

JoeFallon1 replied on Thursday, February 12, 2009

See page 497 of the book to review how the Connection manager works to retrieve connection strings from the app.config file.

You should be able to set up multiple connection strings and then just request any one of them to be used.

Joe

 

Copyright (c) Marimer LLC