471,596 Members | 804 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

SQL Server connection string - how do you normally store or build

I just wonder what is/are your practices to build the SQL Server connection
string?
Use object to build the connection string from config file or somewhere?
Sep 12 '08 #1
2 1529
Man T wrote:
I just wonder what is/are your practices to build the SQL Server connection
string?
Use object to build the connection string from config file or somewhere?
Usually you don't build the connection string dynamically. If you need
to connect to different databases you can keep sepearate connection
strings for them or create them from a template with a simple replacement.

The config file is a good place to store a connection string. Then you
don't have to recompile if the database settings change.

--
Göran Andersson
_____
http://www.guffa.com
Sep 12 '08 #2
"Man T" <al**************@yahoo.com.auwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I just wonder what is/are your practices to build the SQL Server connection
string?
Use object to build the connection string from config file or somewhere?
If you are using version 2.0 or above of the Framework, you can use the
SqlConnectionStringBuilder class. You assign values to the various
properties of a SqlConnectionStringBuilder object, and you can then extract
the completed connection string from its ConnextionString property.
This is only needed if you are going to build it on-the-fly from values
that are "found out" during runtime. If the values in the connection string
are known beforehand, it is a common practice to simply store the completed
connection string in a config file.

Sep 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Fred Zuckerman | last post: by
3 posts views Thread by Terri | last post: by
12 posts views Thread by Dave Bailey | last post: by
9 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.