Sample Web Connection

srideout2525

Registered User.
Local time
Today, 03:57
Joined
Mar 4, 2003
Messages
81
I've been messing with FrontPage and code and this and that to try to simple retrieve data from a database in a web browser. I'm having zero luck. Is there a sample somewhere I could follow? I would be simpy happy to SEE a field from a database in Internet Explorer. Ok I'm not proficent in ASP or PHP, so i'm not sure where to start. I've checked the posting and well, I think I need a step back from what is posted.

Any help...thx!
 
There are lots of ways to connect to databases on the web. Here are some that I use in ASP. It uses a case statement.

My Settings.asp file
Code:
Application("DBType") = 4

SQL Database
Application("SQLServer") = "SQLSERVER"	
Application("SQLDBase") = "Quote"	       
Application("SQLUser") = "sa"			  
Application("SQLPass") = "sapass"

Microsoft Access
Dim Path, File
Path = Server.MapPath("../db/")
File = Path+"\"+"Quote2002.mdb"
Application("AccessPath") = File

DSN Method
Application("DSN_Name") = "QuoteDSN"

You schoose which method you want to use in the Application("DBType") line.

My Public.asp file which holds the Function CreateCon that connects to the database.
Code:
Function CreateCon
   Dim strConn, cnnDB
   Select Case Application("DBType")
      Case 1	' SQL Sec
	strConn = "Provider=SQLOLEDB.1;Data Source=" & Application("SQLServer") & _
              ";Initial Catalog=" & Application("SQLDBase") & _
              ";uid=" & Application("SQLUser") & ";pwd=" & Application("SQLPass")
Case 2	' SQL Integrated Sec
			strConn = "Provider=SQLOLEDB.1;Data Source=" & Application("SQLServer") & _
			  ";Initial Catalog=" & Application("SQLDBase") & ";Integrated Security=SSPI"

		Case 3	' Access
			strConn = "Provider=Microsoft.Jet.OLEDB.4.0" & _
			  ";Data Source=" & Application("AccessPath")
		Case 4	' DSN
			strConn = "DSN=" & Application("DSN_Name")

	End Select

If Not Application("Debug") Then
		On Error Resume Next
	End If
Set cnnDB = Server.CreateObject("ADODB.Connection")
	cnnDB.Open(strConn)

	Set CreateCon = cnnDB

	If Err.Number <> 0 Then
		Call TrapError(Err.Number, Err.Description, Err.Source)
	End If
End Function

Now that you have the variables setup all you have to do is call the function on your page and your set.
Code:
Dim cnnDB
    Set cnnDB = CreateCon

And now you are connected.

Simple:D
 

Users who are viewing this thread

Back
Top Bottom