none
Get the datasourcename from connection string programatically? RRS feed

  • Question

  • I need to get the datasourcename from connectionstrings which is in App.config, prgramatically through C# code, in windows app(Visual Studio 2005)

     

     Can someone show me the code for it?

     

    here is the connection string

     

    <connectionStrings>

    <add name="FusionString" connectionString="User ID=admin;Password=admin;Initial Catalog=Fusion;Data Source=Server2K;"/>

    </connectionStrings>

     

    Thanks. 

     

    Thursday, July 19, 2007 5:25 PM

Answers

  • A possible solution is:

     

    add a reference to System.Configuration.dll

     

    using System.Configuration;

    using System.Data.SqlClient;

     

    string connectionString = ConfigurationManager.ConnectionStrings ["FusionString"].ConnectionString;

    SqlConnectionStringBuilder parser = new SqlConnectionStringBuilder (connectionString);

    string dataSource = parser.DataSource;

     

    HTH

    -mc

     

     

    Thursday, July 19, 2007 6:04 PM

All replies

  • A possible solution is:

     

    add a reference to System.Configuration.dll

     

    using System.Configuration;

    using System.Data.SqlClient;

     

    string connectionString = ConfigurationManager.ConnectionStrings ["FusionString"].ConnectionString;

    SqlConnectionStringBuilder parser = new SqlConnectionStringBuilder (connectionString);

    string dataSource = parser.DataSource;

     

    HTH

    -mc

     

     

    Thursday, July 19, 2007 6:04 PM
  • Awesome man!!!

     

    Thanks Mario.

    Thursday, July 19, 2007 6:54 PM