Support - DSN-less Connection
Web programming models, such as ASP and ASP.Net, key around database connections to create dynamic content on websites. Microsoft provided this in the past using ODBC connections attached to "Data Source Names" (DSN). These names pointed to a data source, like SQL Server or Microsoft Access databases. However, in a shared hosting environment, there are new tools to easily allow customers to create their own DSN's. Microsoft changed their technologies to allow for "DSN-less" connections to databases. Following are example coding that you can use to connect your ASP or ASP.Net application to your database without the use of a DSN. The best way to setup the connection string is to define it in either the web.config file (ASP.Net) or global.asa (ASP).
In the following code, the convention is:
SQLServerName = SQL Server name or IP Address
SQLDBName = SQL Server Database name
MDBPath = Path on your website to the MDB
MDBName.mdb = The name of your Access DB file
DBUser = Your database username for either Access or SQL
DBPass = Your database password for either Access or SQL
Server.MapPath(".") = When the file containing this code is located in the base root of your website, it creates a string with the path information to the folder of the file.
When using the strings in the setup files, web.config or global.asa, it is best to define them as either session or application variables to be accessed anywhere in your code. Then, reference the variable in the connection string areas on each page rather than rewriting the string every time you access the database.
Net Connection Strings
VB.Net Programming
For SQL Server ODBC Driver
Imports System.Data.Odbc
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = _
"Driver={SQL Server};" & _
"Server=SQLServerName;" & _
"Database=SQLDBName;" & _
"Uid=DBUser;" & _
"Pwd=DBPass"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For Access (JET) ODBC Driver
Imports System.Data.Odbc
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & Server.MapPath(".") & "MDBPathMDBName.mdb;" & _
"Uid=Admin;" & _
"Pwd="
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For Access (JET) OLE DB Provider
Imports System.Data.OleDb
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath(".") & "MDBPathMDBName.mdb;" & _
"User ID=Admin;" & _
"Password="
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
For SQL Server OLE DB Provider
Imports System.Data.OleDb
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
"Provider=sqloledb;" & _
"Data Source=SQLServerName;" & _
"Initial Catalog=SQLDBName;" & _
"User Id=DBUser;" & _
"Password=DBPass"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
SQL Server .NET Data Provider
Imports System.Data.SqlClient
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" & _
"Data Source=SQLServerName,1433;" & _
"Initial Catalog=SQLDBName;" & _
"User ID=DBUser;" & _
"Password=DBPass"
oSQLConn.Open()
C# Programming
For SQL Server ODBC Driver
using System.Data.Odbc;
OdbcConnection oODBCConnection = new OdbcConnection();
oODBCConnection.ConnectionString = "Driver={SQL Server};" +
"Server=SQLServerName;" +
"Database=SQLDBName;" +
"Uid=DBUsere;" +
"Pwd=DBPass";
oODBCConnection.Open();
For Access (JET) ODBC Driver
Imports System.Data.Odbc;
OdbcConnection oODBCConnection = new OdbcConnection();
oODBCConnection.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" +
"Dbq=" + Server.MapPath(".") + "MDBPathMDBName.mdb;" +
"Uid=Admin;" +
"Pwd=";
oODBCConnection.Open();
For Access (JET) OLE DB Provider
using System.Data.OleDb;
OleDbConnection oOleDbConnection = new OleDbConnection();
oOleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath(".") + "MDBPathMDBName.mdb;" +
"User ID=Admin;" +
"Password=";
oOleDbConnection.Open();
For SQL Server OLE DB Provider
using System.Data.OleDb;
OleDbConnection oOleDbConnection = new OleDbConnection();
oOleDbConnection.ConnectionString = "Provider=sqloledb;" +
"Data Source=SQLServerName;" +
"Initial Catalog=SQLDBName;" +
"User Id=DBUser;" +
"Password=DBPass";
oOleDbConnection.Open();
SQL Server .NET Data Provider
using System.Data.SqlClient;
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" +
"Data Source=SQLServerName,1433;" +
"Initial Catalog=SQLDBName;" +
"User ID=DBUser;" +
"Password=DBPass";
oSQLConn.Open();
For ASP
OLE DB Provider for Microsoft Jet
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath(".") & "MDBPathMDBName.mdb;" & _
"User Id=admin;" & _
"Password="
OLE DB Provider for SQL Server
oConn.Open "Provider=sqloledb;" & _
"Network Library=DBMSSOCN;" & _
"Data Source=SQLServerName,1433;" & _
"Initial Catalog=SQLDBName;" & _
"User ID=DBUser;" & _
"Password=DBPass"




