Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#2.0 database
How to get :
- database
- server
- user
- password
- is integrated security
from connection string
Database=DbName;Server=SomeServer;Integrated Security=SSPI;
Database=DbName;Server=SomeServer;User Id=myUsername;Password=myPassword;
Posted 21-Mar-10 23:38pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
builder.ConnectionString = ConfigurationManager.ConnectionStrings["inventoryDBConnection"].ConnectionString; ;
string server = builder["Data Source"] as string;
string database = builder["Initial Catalog"] as string;
string UserID = builder["User ID"] as string;
string password = builder["Password"] as string;


This way you can get all the properties.
You may find more help from this MSDN's link:
msdn's link
Hope this will help you.
ProgramFOX at 22-Dec-12 12:12pm
This is a question from 2 years ago. Why do you answer to it? The question is solved already.
jibesh at 22-Dec-12 19:29pm
:O thats interesting how the author dig this out where plenty of unanswered question left unattended!!
dhruvsheth at 23-Dec-12 8:05am
sorry boss but I was searching for same question and i found this link where i didn't found appropriate ans. so did. so someone will be helped.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have to parse the string. There are a couple of ways to do it, and which way you do it is completely based on your own needs.
0) You can use the string.Split method, splitting on the ';' character, and then parsing the resulting substrings
1) You can use the string.IndexOf() method that walks the string looking for specific items.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Did you got a chance to look at:
SqlConnection..::.ConnectionString Property[^]
Once you assign the connection string to SqlConnection object, you can access them separately.
For ex:
using (SqlConnection conn = new SqlConnection())
    conn.ConnectionString = connectionString;
    // Like this:
    //  conn.DataSource
    //  conn.Database

    //  some work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 205
2 Prakriti Goyal 177
3 jlopez788 134
4 _Amy 110
0 OriginalGriff 6,762
1 Sergey Alexandrovich Kryukov 5,539
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505

Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100