NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

NerdyHearn - Blog


<< 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

Implementing AJAX with PHP and MySQL
Reading A Database Schema in SQLite with C#
Reading Digital Signatures from InfoPath Forms in MOSS 2007 and WSS 3.0 Workflow
Copy a DLL from the GAC
Reading a Microsoft Project file (mpp) in C#

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations