Home
IPhone SMS To Gmail
Consulting
Blog
Software
Projects
Links
About
Contact
Blog
Facebook
Twitter
LinkedIn
|
<< Back To All Blogs
ConnectionString Switcharoo
Friday, November 3rd, 2006
I deal with lots of different kinds of Connection Strings in my applications, whether it be from my legacy MySql server still backing the majority of my site, Sql Server 2000 or Sql Server 2005 on some of the newer parts, or a DB2 or PostgreSQL connection that I'm using on a side-project. A problem I often run into is forgetting how to construct the proper connection string for each server type. Granted they are somewhat similiar, but oftentimes not interchangeable. So... my solution: write a program that you can pass generic values, such as username, password, etc to a class I created, call a function with an enum to return the proper connection string. As a coded example:
ConnectionStringBuilder builder = new ConnectionStringBuilder("myUsername", "myPassword", "myServer", "myDatabase");
string connString = builder.GetConnectionString(ConnectionStringTypes.Oracle);
Or, a shorter by-pass method that I am growing on without actually instantiating a full object is:
string connString = new ConnectionStringBuilder("myUsername", "myPassword", "myServer", "myDatabase").GetConnectionString(ConnectionStringTypes.Oracle);
I'll be posting the code to this as well as a bunch of other projects I've been working on lately once I get my new dorky site up for posting code.
That's all for now folks!
Tags
Databases
CSharp
Related Blogs
Reading A Database Schema in SQLite with C#
Implementing AJAX with PHP and MySQL
Enumerating the values of an enum in C#
Determining if a computer is a laptop or desktop in C#
Code Analysis with NDepend V3
Comments
Currently no comments.
Add A Comment
Name:
URL:
Email Address: (not public, used to send notifications on further comments)
Comments:
Please enter the text from the image:

|