milani_lucie
asked on
Getting connection information from connection string (App.Config) .... VB.NET / C#
Hi,
I want to get connection information from connection string:
1) Provider Name
2) Database Name
3) Server Name
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DigiBrd"
connectionString="server=l ocalhost;u ser id=****;Password=****;data base=DigiB rd"
providerName="MySql.Data.M ySqlClient " />
</connectionStrings>
</configuration>
etc...
I do NOT want to parse the CONFIG file. I think so after reading the connection string, there are API methods / properties to get that info.
Thanks
I want to get connection information from connection string:
1) Provider Name
2) Database Name
3) Server Name
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DigiBrd"
connectionString="server=l
providerName="MySql.Data.M
</connectionStrings>
</configuration>
etc...
I do NOT want to parse the CONFIG file. I think so after reading the connection string, there are API methods / properties to get that info.
Thanks
Also, you need to reference the System.configuration.dll into your project so your ConfigurationManager object will function properly.
:)
:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I mentioned that "To get database name one more option there.".
I show option to to get Database name from SqlConnection object. I don't repeat your code.
I show option to to get Database name from SqlConnection object. I don't repeat your code.
Look carefully at our posts #1 and #2, see if you have similar codes.
kaufmed also have the code already in his first code highlight. Below is the code you also duplicate:
string providerName = System.Configuration.Confi gurationMa nager.Conn ectionStri ng["DigiBr d"].Provid erName;
string providerName = System.Configuration.Confi
@armchang
While I appreciate that we are all trying to help milani_lucie, please realize that your original post only clarifies how to get the connection string, and not how to get the individual parts of the connection string. Specifically, the parts in question are:
Your post does not demonstrate how to access these individual parts. Does the code posted by myself and others duplicate yours--yes, but only to a point. And that duplication was necessary to properly answer the question.
While I appreciate that we are all trying to help milani_lucie, please realize that your original post only clarifies how to get the connection string, and not how to get the individual parts of the connection string. Specifically, the parts in question are:
Provider Name
Database Name
Server Name
Database Name
Server Name
Your post does not demonstrate how to access these individual parts. Does the code posted by myself and others duplicate yours--yes, but only to a point. And that duplication was necessary to properly answer the question.
P.S.
I even gave you credit in my post ; )
I even gave you credit in my post ; )
using System.Configuration;
string str = ConfigurationManager.Conne