How do I define a connection string for the database server?
For MS SQL Server, used with the SQL Server data provider, we can write the connection string like:
C# Version
// for Sql Server
string connectionString = "server=P-III; database=programmersheaven;" +_
"uid=sa; pwd=;";
VB.Net Version
' for Sql Server
Dim connectionString As String = "server=P-III; database=programmersheaven;" + _ "uid=sa; pwd=;"
First of all we have defined the instance name of the server, which is P-III on my system. Next we defined the name of the database, user id (uid) and password (pwd). Since my SQL server doesn't have a password for the System Administrator (sa) user, I have left it blank in the connection string. (Yes I know this is very dangerous and is really a bad practice - never, ever use a blank password on a system that is accessible over a network)
For Oracle Database Server, used with the Oracle data provider, we can write the connection string like:
C# Version
string connectionString = "Data Source=Oracle8i;User Id=username;" +
"Password=pwd; Integrated Security=no;";
VB.Net Version
Dim connectionString As String = "Data Source=Oracle8i;User Id=username;" + _
"Password=pwd; Integrated Security=no;"
For MS Access Database, used with the OLE DB data provider, we can write the connection string like:
C# Version
// for MS Access
string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;" +
"data source = c:\\programmersheaven.mdb";
VB.Net Version
' for MS Access
Dim connectionString As String = "provider=Microsoft.Jet.OLEDB.4.0;" + _
"data source = c:\programmersheaven.mdb"
First we have defined the provider of the access database. Then we have defined the data source which is the address of the target database.
For MS SQL Server, used with the ODBC data provider, we can write the connection string like:
C# Version
string connectionString = "Driver={SQL Server};Server=FARAZ;Database=pubs;Uid=sa;Pwd=;";
VB.Net Version
Dim connectionString As String = "Driver={SQL Server};Server=FARAZ;Database=pubs;Uid=sa;Pwd=;"
Back