
Signature
Luigi
http://blogs.dotnethell.it/ciupaz/
Hi Luigi,
I haven't tested this, but if you create an SqlConnection it has a Database
property that might hold the value you need. If the connection string is in
a specific format, you could also just parse the string, but connection
strings can come in many flavours (see www.connectionstrings.com).

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> Hi all,
> how can I obtain the dabase name from a connectionString retrieved from a
[quoted text clipped - 5 lines]
>
> Luigi
Luigi - 07 Jan 2008 10:04 GMT
> Hi Luigi,
>
> I haven't tested this, but if you create an SqlConnection it has a Database
> property that might hold the value you need. If the connection string is in
> a specific format, you could also just parse the string, but connection
> strings can come in many flavours (see www.connectionstrings.com).
Hi Morten,
yes, finally I've made like this:
string connString =
ConfigurationManager.ConnectionStrings["PrideConnectionString"].ToString();
SqlConnection connection = new SqlConnection(connString);
string database = connection.DataSource.ToString();
if (database == "MILDBBP2S")
this.lblCurrentEnviroment.Text = "Produzione";
else if (database == "MILDBBP2STEST")
this.lblCurrentEnviroment.Text = "Test";
else
this.lblCurrentEnviroment.Text = "Server unknown";
Thanks so much.
Luigi
Nicholas Paldino [.NET/C# MVP] - 07 Jan 2008 16:39 GMT
You can also use the SqlConnectionString class, which will give you more
detailed information about the individual properties of the connection
string. It inherits from the DbConnectionStringBuilder, which most
providers should provide an implementation of to help with encapsulating the
logic of constructing (and parsing) connection strings.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>> Hi Luigi,
>>
[quoted text clipped - 26 lines]
>
> Luigi