Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Calling Database
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

thespacegeek
Starting Member

10 Posts

Posted - 13 April 2001 :  13:04:59  Show Profile
I am developing a site, and I want to a db from a function. How do I do this? I have tried SEVERAL ways to do it, but they have all been to no avial. I am using a DNS-less connection to MS-ACcess.

Thanks

Doug G
Support Moderator

USA
6493 Posts

Posted - 13 April 2001 :  15:43:55  Show Profile
How about some details, like what several ways you've tried without success. I have no clue what you want to accomplish.


======
Doug G
======
Go to Top of Page

thespacegeek
Starting Member

10 Posts

Posted - 14 April 2001 :  16:31:14  Show Profile
This is just a sample of what I have tried. This is my orginail attempt. It didn't work.

This is in an inlude file at the top of the page.
Function OpenDB()
Set Conn= Server.CreateObject("ADODB.Connection")
Connstr= "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
Connstr=Connstr & "DATA SOURCE=" & server.mappath("/db.mdb") & ";"
Conn.Open(connstr)
END Function

Function closedb ()
Conn.Close
Set Conn=Nothing
End Function


On the page:
opendb()
SQL="EXEC query_auth_empl " & id
Set RS = Conn.Execute(SQL)
state=RS_auth_empl("waterp_state")
closedb()



Edited by - thespacegeek on 14 April 2001 20:03:59
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 14 April 2001 :  20:39:43  Show Profile
Are you using Option Explicit in your code?

Unless you Dim'd Conn at a higher level than you've shown, Conn will disappear when you exit your function, it's scope is local to the function.

You can return Conn as the result of your function, or you can make sure Conn has global scope by Dim-ing it at the very top of your page not in a function or sub.

If you want to return Conn as the result of your function, do something like this:

Function OpenDB()
Set Conn= Server.CreateObject("ADODB.Connection")
Connstr= "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
Connstr=Connstr & "DATA SOURCE=" & server.mappath("/db.mdb") & ";"
Conn.Open(connstr)
Set OpenDB = Conn
END Function

And call as

Set ThisConn = OpenDB()



======
Doug G
======
Go to Top of Page

thespacegeek
Starting Member

10 Posts

Posted - 15 April 2001 :  08:11:21  Show Profile
Thanks.
That works perferctly.


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.37 seconds. Powered By: Snitz Forums 2000 Version 3.4.07