Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 database
Hi,

How to get :
- database
- server
- user
- password
- is integrated security

from connection string
Database=DbName;Server=SomeServer;Integrated Security=SSPI;
or
Database=DbName;Server=SomeServer;User Id=myUsername;Password=myPassword;
Posted 22-Mar-10 0:38am
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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

<pre>
//
//  some work

}
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Quote:
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;</blockquote>

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.
Thanks.
  Permalink  
Comments
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.

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

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 335
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200
0 OriginalGriff 465
1 Sergey Alexandrovich Kryukov 275
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2015
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