Click here to Skip to main content
13,094,193 members (53,353 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 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
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 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 22-Dec-12 19:29pm
:O thats interesting how the author dig this out where plenty of unanswered question left unattended!!

dhruvsheth 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.
VBNetHack 13-Jun-17 12:36pm
Well nearly five years later I found your answer helpful, thanks dhruvsheth :)
dhruvsheth 28-Jun-17 1:38am
Thanks for appreciating.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2017
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