Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection not working

Status
Not open for further replies.

gcole

Programmer
Aug 2, 2000
390
US
This is my code, I simply want to open the table.

<HTML>
<HEAD><TITLE>A Simple First Page</TITLE>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Option Explicit

Function SQLQuote(var)
If InStr(var, &quot;'&quot;) <> 0 Then
var = Replace(var, &quot;'&quot;, &quot;''&quot;)
End If

SQLQuote = var
End Function

'framework variables...
Dim objDB
Dim objRS
Dim sDBName
Dim sAction
Dim sRowColor
Dim html
Dim sql
Dim sError

sDBName = &quot;driver={Microsoft Access Driver (*.mdb)};dbq=c:\websites\kdc\fpdb\backend.mdb&quot;
Set objDB = Server.CreateObject(&quot;ADODB.Connection&quot;)
objDB.Open sDBName

-->
</SCRIPT>
</HEAD>
<BODY>


</BODY>
</HTML>

 
If u are using Acess do not replace ' because this is in SQL statments
U dont have to use function SQLQuote...

Set Connection = Server.CreateObject( &quot;ADODB.Connection&quot; )
Connection.Open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=c:\websites\kdc\fpdb\backend.mdb&quot;

Const adOpenStatic = 3
Const adUseClient = 3
Const adLockPessimistic = 2

set rs=server.CreateObject(&quot;ADODB.Recordset&quot;)

sub ExecuteSQL(byval cmd)
if rs.State=1 then rs.close
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockPessimistic
rs.Source = cmd
rs.ActiveConnection = Connection 'The record set needs to know what connection to use.
rs.Open
end sub
....
SQL=&quot;select * from MyTable&quot;
ExecuteSQL(SQL)
nrrec=rs.RecordCount
if nrrec=0 then
'we dont have recordsets
rs.Close
Connection.Close
set rs=nothing
set Connection=nothing
end if
.... ________

George
 
It looks like you forgot a set of quotes before dbq.

good Luck.

Russ
 
I have tried both sets of code (above and mine). I am getting a variable server not defined. Do you think the problem is my ODBC connection?
 
If u are getting an error &quot;variable server not defined.&quot;
It may be IIS problem cuz didnt create object or maybe u dont have &quot;ADODB.Connection&quot; object
Try to find in your registry (regedit.exe) &quot;ADODB.Connection&quot; if u dont have then u have to install it... ________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top