1

I want to change the dataset table adapter connection string at run time. Now i have a code to change that connection string but it change the server name only not changing database name, username and passowrd. Please help me to fix this error..

This is my partial code :

   Properties.Settings.Default["testConnectionString"] = String.Format("server={0};Port={1}; database={2};User Id={3};password={4}", "172.23.2.32", "3306", "hrm", "root", "test123");

The above code only change the ip address and data inserted into database.But now am change the database name means data inserted into "hrm" database. Please help me to fix this ...

Amulraj
  • 269
  • 4
  • 10
  • 21

1 Answers1

0

I conducted an experiment with properties and was able to get User settings to change just fine.

Settings File

enter image description here

Notice that the difference between these two values is in the Scope. User settings can change at runtime. Application settings cannot change at runtime.

Code

class Program
{
    static void Main(string[] args)
    {
        //Application Properties can not change. They are read only
        //Properties.Settings.Default.testConnectionStringApplication 
        //    = String.Format("server={0};Port={1}; database={2};User Id={3};password={4}", "172.23.2.32", "3306", "hrm", "root", "test123");

        //User Properties can change
        Properties.Settings.Default.testConnectionStringUser
            = String.Format("server={0};Port={1}; database={2};User Id={3};password={4}", "172.23.2.32", "3306", "hrm", "root", "test123");

        //Call Save to persist the settings. 
        Properties.Settings.Default.Save();

        Console.WriteLine(Properties.Settings.Default.testConnectionStringUser);
        Console.ReadLine(); 
    }
}

Output

enter image description here

Source

How To: Write User Settings at Run Time with C#

Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
  • Thanks for your reply. Am using the above code but it returns the exact connections string. But DataSet1TableAdapter.sp_getallemployeepunch1 TA =new DataSet1TableAdapter.sp_getallemployeepunch1(); TA.GetData(String, String .,); read the above connection string but the value stored in another database table. – Amulraj Jun 08 '12 at 17:12
  • For example i was create a table adapter using dataset -> use existing stored procedure -> in select statement ->(specify existing stored procedure name)-> check(fill a datatable & get a datatable )option and -> finish. – Amulraj Jun 08 '12 at 17:21