C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

All Sample Connection String for All database using C#.Net and VB.Net


Posted Date: 03 Jun 2009    Resource Type: Code Snippets    Category: Visual Studio
Author: Manoranjan SahooMember Level: Gold    
Rating: 1 out of 5Points: 30



Connection string for all database.


Here you can find all connection string for all database using C#.Net and VB.Net

Microsoft SQL Server .NET Data Provider (NameSpace : System.Data.SqlClient)


The Microsoft SQL Server .NET Data Provide allows you to connect to a Microsoft SQL Server databases.
Using C#:

using System.Data.SqlClient;
...
SqlConnection SQLConn = new SqlConnection();
SQLConn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabaseName;User ID=myUsername;"Password=myPassword" ;
SQLConn.Open();
...
SQLConn.Close();

Note : If you open the connection, then close the connection. Otherwise the connection does not go back into the connection pool. The SqlDataAdapter will open and close the connection for you when calling it's Fill or Update methods. However if the connection is already open, the SqlDataAdapter will leave it open.
Using VB.NET:

Imports System.Data.SqlClient
...
Dim SQLConn As SqlConnection = New SqlConnection()
SQLConn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabaseName;"User ID=myUsername;Password=myPassword"
SQLConn.Open()
...
SQLConn.Close()

If connect to a remote server (via IP address):

SQLConn.ConnectionString = _
"Network Library=DBMSSOCN;" Data Source=xxx.xxx.xxx.xxx,1433;Initial Catalog=myDatabaseName;User ID=myUsername;Password=myPassword"
SQLConn.Open()
...
SQLConn.Close()

ODBC .NET Data Provider (NameSpace : System.Data.Odbc)


The Open Database Connectivity (ODBC) .NET Data Provider provides access to database.

For SQL Server ODBC Driver


USING C#.NET


Using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString = "Driver={SQL Server};Server=MySQLServerName;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword" ;
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String = "Driver={SQL Server};Server=MySQLServerName;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Oracle ODBC Driver


USING C#.NET


Using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString = "Driver={ Microsoft ODBC for Oracle };Server= OracleServer.world;Database=MyDatabaseName;Uid=MyUsername;Pwd=MyPassword" ;
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=myUsername;Pwd=myPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Access (JET) ODBC Driver


USING C#.NET


using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString ="Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;";
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For Sybase System 11 ODBC Driver


USING VB.NET


Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Driver={Sybase System 11};SRVR=mySybaseServerName;DB=myDatabaseName;UID=myUsername;PWD=myPassword"
ODBCConnection = New OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

For all other ODBC Drivers
USING C#.NET


using System.Data.Odbc ;
...
OdbcConnection ODBCConnection;
string ConnString ="Dsn=myDsn;Uid=myUsername;Pwd=myPassword";
ODBCConnection = New Odbc.OdbcConnection(ConnString) ;
ODBCConnection.Open() ;
...
ODBCConnection.Close() ;

USING VB.NET

Imports System.Data.Odbc
...
Dim ODBCConnection As OdbcConnection
Dim ConnString As String ="Dsn=myDsn;Uid=myUsername;Pwd=myPassword"
ODBCConnection = New Odbc.OdbcConnection(ConnString)
ODBCConnection.Open()
...
ODBCConnection.Close()

OLE DB .NET Data Provider (NameSpace : System.Data.OleDb)


The Microsoft .NET Framework Data Provider for OLE DB allow you to use native OLE DB providers (e.g. Microsoft.JET.OLEDB.4.0) to access database.

For JET OLE DB Provider


USING C#.NET


using System.Data.OleDb ;
...
OleDbConnection OleDbConnection;
string ConnString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myPath\myJet.mdb;User ID=UserID;Password=Password" ;
OleDbConnection = New OleDb.OleDbConnection(ConnString);
OleDbConnection.Open() ;
...
OleDbConnection.Close();

USING VB.NET

Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myPath\myJet.mdb;User ID=UserID;Password=Password"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For IBM AS/400 OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String = "Provider=IBMDA400.DataSource.1;Data source=myAS400DbName;User Id=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For Oracle OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String =Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User ID=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()

For SQL Server OLE DB Provider


USING VB.NET


Imports System.Data.OleDb
...
Dim OleDbConnection As OleDbConnection
Dim ConnString As String ="Provider=sqloledb;Data Source=myServerName;Initial Catalog=myDatabaseName;User Id=myUsername;Password=myPassword"
OleDbConnection = New OleDb.OleDbConnection(ConnString)
OleDbConnection.Open()
...
OleDbConnection.Close()


Thank You.

Regards,
Manoranjan Sahoo
Visit My Blog: http://msahoo.wordpress.com




Responses

Author: Miss Meetu Choudhary    05 Jun 2009Member Level: Diamond   Points : 1
Good One!!!

All Combinations under one roof...

I liked th concept...

keep it up...


Author: Manoranjan Sahoo    06 Jun 2009Member Level: Gold   Points : 1
if anyone want more connection string then reply here i will update that one.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SQL server  .  Oracle  .  ODBC  .  Database connectivity  .  Connection String  .  Connect to database  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Dynamically add item to dropdown list
Previous Resource: Best way to extract Numbers from a string
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use