Results 1 to 6 of 6

Thread: [RESOLVED] [2005]Update Connection String

Threaded View

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved [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=www; 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
    Code:
        objConfig.Save();
    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 vuyiswamb; Mar 2nd, 2009 at 08:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width