<%@ LANGUAGE=VBSCRIPT%> Create a DSN-Less Database Connection <% ON ERROR RESUME NEXT Dim sConnection Dim VirtualPath VirtualPath = "server.mappath(" & """" & "/database" if not isnull(Request("Provider")) then ' Build the Connection String SELECT Case Request("Provider") CASE "Microsoft Access" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;User ID=" & Request("UserName") & ";Password=" & Request("Password") & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Microsoft Excel 95" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 5.0" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Microsoft Excel 97" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 97" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Microsoft Excel 2000" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "DBase III" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE III" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "DBase IV" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE IV" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "DBase 5" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE 5.0" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" ' Will leave for later CASE "Microsoft FoxPro" sConnection = "" CASE "Paradox 3.x" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Paradox 3.x" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Paradox 4.x" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Paradox 4.x" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Paradox 5.x" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Paradox 5.x" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE "Microsoft SQL Server" sConnection = """" & "Provider=SQLOLEDB.1; Network Library=dbmssocn;" sConnection = sConnection & "Password=" & Request("Password") sConnection = sConnection & ";User ID=" & Request("UserName") sConnection = sConnection & ";Initial Catalog=" & Request("DBName") sConnection = sConnection & ";Data Source=" & Request("SQLServer") & ";" & """" CASE "Text" sConnection = """" & "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text" & ";Data Source=" & """" & " & " sConnection = sConnection & VirtualPath & "/" & Request("Location") & """" & ")" CASE Else sConnection = "" END SELECT end if %>
<%if len(sConnection) > 0 then%> <%else%>
Create DSN-Less Database Connection

Below is your DSN-Less Connection to the Database you Specified. You should be able to Cut and Paste this into your code and test the connection to your Database.

 
Database Connection:  
 

Active Server Page Code Example
 
--- BEGIN CODE COPY HERE ---->
<%@ Language=VBScript %>
<%
' Dim the Recordset Object
Dim rsADO

' Define the Connection String From Above
ConnectionString = <%=sConnection%>

' Create the Object
Set rsADO = Server.CreateObject("ADODB.Recordset")

' Define the SQL Statement
' (REPLACE TABLENAME WITH THE TABLE NAME
' IN YOUR DATABASE)
Source = "SELECT * FROM TABLENAME"
	
' Open the Recordset 
rsADO.Open Source, ConnectionString

' Display the Fields Returned 
' (PUT YOUR FIELD NAMES WHERE FieldName1 and 
' FieldName2 Appear)
Do while(not rsADO.EOF)
	Response.Write rsADO("FieldName1") 
	Response.Write rsADO("FieldName2") 
   rsADO.MoveNext 
Loop

' DeAllocate the Object to Free Server Memory
set rsADO = nothing
%>
<--- END CODE COPY HERE ----
 

 
Create another DSN-LESS Connection
 
Create DSN-Less Database Connection

Choose your Database Type:
Database Location (Relative - Non SQL):
SQL Server Name (SQL Only):
Database Name (SQL Only):
User Name:
Password:
 
 
<%end if%>  

This function demonstrates how to use DSN-Less strings on connecting database.

Click here for help.

** For more information about creating a DSN-Less Connection String using OLEDB 4.0 use the following link.
Microsoft Technical Article - Opening a Database (OLEDB 4.0)