Virtual Domain Hosting

Database Access


Preliminary info about referencing databases

If you host a domain with us, you can use one or more databases with your site (e.g.: Microsoft Access, Microsoft SQL Server, Microsoft Visual FoxPro, etc.) Take a look at the information below for information, tips, etc. regarding incorporating a database into your website.

ASP.NET 2.0 - 4.0

ASP.NET users do not need and should not use DSNs (data source names) to access databases. ASP.NET can directly access databases which is more efficient than using ODBC DSNs.
Sample /Web.config file:
<?xml version="1.0" ?> <connectionStrings> <!-- The following two connectionString values are identical. http://msdn.microsoft.com/en-us/library/ms998292.aspx --> <add name="MyDbConn1" connectionString="Server=SQLServerName;Database=MyDatabaseName;Trusted_Connection=Yes;"/> <add name="MyDbConn2" connectionString="Data Source=SQLServerName;Initial Catalog=MyDatabaseName;Integrated Security=SSPI;"/> </connectionStrings>

ASP (Active Server Pages)

ASP users do not need and should not use DSNs (data source names) to access databases. ASP can directly access databases which is more efficient than using ODBC DSNs.
Sample /global.asa file:
<SCRIPT LANGUAGE=vbscript RUNAT=Server> ' Use the following METADATA line instead of referencing ' C:\Program Files\Common Files\System\ado\adovbs.inc <!--METADATA TYPE="typelib" UUID="2A75196C-D9EB-4129-B803-931327F72D5C" NAME="Microsoft ActiveX Data Objects 2.8 Library"--> Sub Application_OnStart ' http://msdn.microsoft.com/en-us/library/ms675810.aspx ' http://msdn.microsoft.com/en-us/library/ms681020.aspx ' Use the appropriate connection string (see the above references for details): ' Microsoft SQL Server database: ' http://msdn.microsoft.com/en-us/library/ms677227.aspx Application("ConnectionString") = "Provider=SQLOLEDB;" _ & "Data Source=SQLServerName;" _ & "Database=MyDatabaseName;" _ & "Integrated Security=SSPI;" ' Microsoft Access database: ' http://msdn.microsoft.com/en-us/library/ms681754.aspx Application("ConnectionString") = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" & Server.MapPath("/db/MyDatabaseFile.mdb") & ";" _ & "User ID=MyUserID;" _ & "Password=MyPassword;" End Sub </SCRIPT>
Sample ASP file that references the database: example.asp
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link href="/ssi/default.css" rel="stylesheet" type="text/css"> <title>Sample ASP page referencing a database</title> </head> <body> <!-- Various other HTML code... --> <% Call ConnectToDatabase %> <!-- Various other HTML code... --> </body> </html> <% Sub ConnectToDatabase Dim dbConn, SQL, MemberList SQL = "EXECUTE sp_MyStoredProcedure" ' or some other SQL command such as ' "SELECT FirstName, LastName, Age FROM Members " _ ' "WHERE Age >= 25 ORDER BY LastName, FirstName" Set dbConn = Server.CreateObject("ADODB.Connection") dbConn.ConnectionString = Application("ConnectionString") ' from the /global.asa file ' Set the connection permissions--use adModeRead (read-only) when possible: dbConn.Mode = adModeRead ' http://msdn.microsoft.com/en-us/library/ms675792.aspx dbConn.Open Set MemberList = dbconn.Execute(SQL,,adCmdText) Do While Not MemberList.EOF Response.Write MemberList("FirstName") & " " & MemberList("LastName") _ & " - " & MemberList("Age") & "<br>" & vbcrlf MemberList.MoveNext Loop ' Clean up as soon as you're finished using the database! MemberList.Close Set MemberList = Nothing dbConn.Close Set dbConn = Nothing End Sub %>

ColdFusion

ColdFusion 5 users should use OLEDB DSNs (data source names) instead of ODBC DSNs to access their databases. Network Tallahassee can create DSNs on the web server for you. See the following information at Adobe's website:
Using Microsoft Access Databases in a Production Environment (also includes information about using OLEDB and ODBC)
Sample /Application.cfc file (ColdFusion MX):
<cfcomponent> <cfset This.name="MyWebSite"> <cffunction name="onApplicationStart"> <cfset application.dsn="MyDSNname"> </cffunction> </cfcomponent>
Sample /Application.cfm file (ColdFusion 5):
<cfapplication name="MyWebSite"> <cfset application.dsn="MyDSNname">
Sample ColdFusion file that references the database: example.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link href="/ssi/default.css" rel="stylesheet" type="text/css"> <title>Sample ColdFusion page referencing a database</title> </head> <body> <!--- Various other code... ---> <cfquery name="MemberList" datasource="#application.dsn#"> EXECUTE sp_MyStoredProcedure <!--- or some other SQL command such as SELECT FirstName, LastName, Age FROM Members WHERE Age >= 25 ORDER BY LastName, FirstName ---> </cfquery> <cfoutput query="MemberList"> #FirstName# #LastName# - #Age#<br> <cfoutput> <!--- Various other code... ---> </body> </html>