|
-
March 2nd, 2009, 07:56 AM
#1
[RESOLVED] [2005]Update Connection String
Good Afternoon
My Application is Structured in a Way that before you login you must First Select a Database. Now i have one page that i want to change the Connection String Database name.
I have this function that get called on page load
Code:
/*This Function will change the Connection string in the web.congif file based on the Database that exists on the
* session Variable. If there is nulll then set odirect3 as a current Database name.
*/
public void UpdateConfig()
{
CommonFunctions obj = new CommonFunctions();
String strKey = "NEWDT";
String StrDatabase;
if (Session["ActiveDatabase"] != null)
{
StrDatabase = Convert.ToString(Session["ActiveDatabase"]);
}
else
{
StrDatabase = "oDirectv3";
}
String strValue = @"User id=sa;Password=wow;Server=drddd;Database="+StrDatabase;
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
if (objAppsettings != null)
{
objAppsettings.Settings[strKey].Value = strValue;
objConfig.Save();
}
}
On the Development site it works well. But while still debugging the code, checking if its doing what i want, There is a point where it has to save the changes
The Part will execute and message box will appear asking me if i really want to save the changes made, i will save yes and everything will be fine. But if i don debug it , it gives an Error that says
Code:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
How can i do this and Suppress this dialogs
Thank you
Last edited by vuyiswam; March 2nd, 2009 at 08:19 AM.
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|