Getting the connection string for a project

I'd like to set a string variable to the connection string for a project. I've seen the build connection string module/function and tried to use it but it's hopelessly complex for what I want.

I just want the string.

Is there an easier way



Answer this question

Getting the connection string for a project

  • RennySchweiger

    LOL!

  • BillMiddlebrook

    I want to get the value of the current Connection string to open a SQLDataReader.

    Eventually, I want to store the Connection string in a separate database on the same server as my SQL database and retrieve it from there.

    I don't know why this is such rocket science. It's only a string of characters.


  • mfroman

    The rocket science is introduced by security concerns. Yay hackers! You make our lives so fun!!!

    As mentioned in the previous post, if you store a vaild database username and password in the connection string, and then store that string in a place that it can be found outside of your app, then anyone who uses your app has the potential to get valid logon credentials to your database server. Then they could make your life miserable by doing all kinds of nasty things to your data.

    Now, to your original question... When you say "connection string for a project", it doesn't really make sense, as one project could have many connnection strings that are used.

    Based on what you've told us, it has to be assumed that the connection string you want to access was generated automatically by some wizard in Visual Studio. What object were you creating when the wizard helped you build the connection string That object should have a ConnectionString (or similarly named) property that contains your value... If the database is connected in the Server Explorer (or Data Sources in VS05), you can check the properties of the connection and get the connection string in use.

    If you are in VS05, then you should be able to use My.Settings.[ConnectionStringName] to access any auto-generated connection strings. Just remember the security issue! The string may not connect properly until to modify it by adding a vaild credential section like: User ID=myusername; Password=mypassword



  • rpjimenez

    Christopher Fleming wrote:

    ...

    Food for thought...why would you want to store a connection string in a database that you need a connection string to access

    ...

    That's not food - it's bubble gum... Just keep chewing on that one!

    Sorry to be snide, couldn't resist! But seriously, Chris is right. Storing a connection string in the database that said string connects to just doesn't make any sense. If you need a way of sharing this string between instances of your application (let's say that something like the servername has a potential to change) then you'll need to use some other intermediate - like an email or fileshare. Just make sure that you strictly limit access to whatever location you store this connection string in.



  • Manaxter

    Well a connection string is an easy thing. What I'm trying to ascertain and I don't think you're providing is where exactly you are hoping to get his value from From an open datacommand object If so that would be MyDataCommand.Connection.ConnectionString. From a SQLConnection directly if so that would be MyConnection.ConnectionString. To even get connected to anything you would have had to provide the connection string in the first place right Why not grab it there for storage purposes If none of these options satisfy your request I think you should post some code so I can better understand what you're asking for.

    Food for thought...why would you want to store a connection string in a database that you need a connection string to access

    Christopher



  • Mochiwala

    Hello. I'm not sure whether you're trying to figure out how to build the connection string or to query an existing one.

    For information on building a connection string the following site is excellent

    www.connectionstrings.com

    As for storage in your application that depends on a lot of factors. If you are using Windows authentication to access your server you'll probably be using "integrated security" which means you can store the connection string just about anywhere such as in an App.config file because it doesn't contain any login or password information. If you are relying on a SQL Login/Password combination and granting this various permissions to your source/destination database then you'll be using a login/password in your connection string meaning you'll likely want to protect this information somehow.

    Christopher



  • tom_ma

    Thanks for the help. You were accurate and succinct.

    By the way, how I deal with Mac fanatics is to let them know that WIndows screen resolution (96 dpi) is higher than the Mac (72 dpi). They never believe me, so I demonstrate by creating a new file from a screen dump in Photoshop. More than one of them has had a nervous breakdown as a result.

    Tom


  • WalidDib

    tomatgdd wrote:

    You guys should chill. You're starting to sound like Mac fanatics.

    Promise that if it ever really gets that bad, you will shoot us all and set fire to the boards

    Ok, then the answer to your question is to use:

    My.Settings.[ConnectionStringName]

    Where [ConnectionStringName] is the name you gave the connection when it was created - by default it will be the name of the database followed by 'ConnectionString'.



  • StackAdder

    LMAO ROFL!!!

    That's gotta be the greatest "one-upper" ever! I can't wait to use that one on my company President, Marketing Developer, and Advertising Manager!!!

    Anyway, don't wanna get too far off topic. Glad that solution worked for ya.

    Good luck!



  • Yin He

    I didn't mean to cause mass hysteria.

    The string is set in the Settings property of the project. I've found the DataSource manager to be unstable and unreliable, so I want to use SQLConnection to get my data directly. I want to reference the project connection string for SQLConnection.

    You guys should chill. You're starting to sound like Mac fanatics.


  • Getting the connection string for a project