|
 |
access_asp thread: Connection problem
Message #1 by Sandra Massett <smassett@s...> on Tue, 15 Jan 2002 10:43:55 -0800
|
|
This is a multi-part message in MIME format.
--Boundary_(ID_MXpBvO7Il19ybY+H16JvRA)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
I have in my global.asa the following code:
<script language="vbscript" runat="server">
sub Application_OnStart
<!-- METADATA TYPE="TypeLib" FILE="D:\Program Files\Common Files\system\ado\msado15.dll" -->
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WebSites\JobSearch\Profile.mdb"
set cn=Server.CreateObject("ADODB.Connection")
cn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & connString & ";uid=;pwd=;"
end sub
</script>
and in my index.asp page I have the following code:
option explicit
dim rsView,sSQL
set rsView = server.createobject("adodb.recordset")
sSQL = "SELECT nCompanyId, sCompanyName, sContactName, dContactDate, sPhone, bContacted, bRejected FROM tbCompany ORDER BY
sCompanyName"
rsView.open sSQL,cn,0,1,adcmdTable
I keep getting the error variable unidentified 'cn' right where I open my recordset.
Can anyone give me a hint of what to try.
Message #2 by smassett@s... on Tue, 15 Jan 2002 18:53:28
|
|
Oh ya I'm using Windows/Access 2000 and IIS 5
Message #3 by "Steffen Wogensen Jaques" <webmaster@w...> on Tue, 15 Jan 2002 20:15:24 +0100
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0025_01C19E01.5D804D90
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hey there,
It appears to me like you need to do quite abit more of reading
regarding ASP :)
but let's go to the code ->
1. The Sub Application_OnStart is run whe the application is first
loaded. That means that the first time a client loads your site up it
will run that Sub. So what you are doing is rather odd ;) -- You see,
you are trying to open a database, but it will only happen that one
time.
2. The tag <!-- METADATA type=3D".. bla bla bla..." --> is intended for
the .asp files as far as I know, andis used to set constants when
needed, so to the best of my knowledge it can't be used where you are
trying to do it, because it is not a valid VBScript statement.
3. When setting variables in global.asa You need to set the "APPLICATION
VARIABLE" .. you do that like this:
Application("variable_name") =3D "whatever value"
and not like this:
variable_name =3D "some other value"
(The difference is that the Application("variable_name") will be
accesible everywhere in the entire application [that means on all the
asp files], and the 'variable_name' will only be accessible in the
global.asa fil -- so you see what you've clearly done wrong)
4. Normally you wouldn't open a database in the global.asa file, unless
you really know what you are doing -- And from what I can see you need a
bit more expirience before you do that :o)
5. In the file you are trying to reference the variable "cn" .. but
remember what I told you at point 3 ? -- That non-application variables
set in the global.asa file aren't accessible outside global.asa .. So
since you have run the statement "Option Explicit" you are trying to
reference a non-set variable, where Option Explicit tells the
interpreter to generate an error if you try to reference a non-existing
variable. So thats why it generates an error.
Now then -- What _should_ you do?
Here ya go:
--- FOR THE GLOBAL.ASA --
<script language=3D"vbscript" runat=3D"server">
Sub Application_OnStart
'This creates a Application variables called "connString" which you can
call from anywhere in your pages
Application("connString") =3D "Provider=3DMicrosoft.Jet.OLEDB.4.0;Data
Source=3DC:\WebSites\JobSearch\Profile.mdb;Persist Security Info =3D
False"
end sub
</script>
---- FOR THE INDEX.ASP ---
<!-- METADATA TYPE=3D"TypeLib" FILE=3D"D:\Program Files\Common
Files\system\ado\msado15.dll" -->
'Turn on error thingy so it will generate errors if you forget to
"Dim" variables
Option Explicit
'Create variables
Dim rsView,sSQL
'Create a recordset object
Set rsView =3D Server.CreateObject("ADODB.Recordset")
'Create the SQL string for selecting the recordset
sSQL =3D "SELECT nCompanyId, sCompanyName, sContactName, dContactDate,
sPhone, bContacted, bRejected FROM tbCompany ORDER BY sCompanyName"
'Open a connecting to the database -- Notice that I am using the
Application variable as the connection string :) And noticew that I have
change the adCmdTable to adCmdText -- this is because we are using SQL
to select records from the database instead of selecting the entire
_table_
rsView.open
sSQL,Application("connString"),adOpenReadonly,adLockOptimistic,adCmdText
--------- END -----
And thats all there is too it.
Kind Regards,
SWJ.
----- Original Message -----
From: Sandra Massett
To: Access ASP
Sent: Tuesday, January 15, 2002 7:43 PM
Subject: [access_asp] Connection problem
I have in my global.asa the following code:
<script language=3D"vbscript" runat=3D"server">
sub Application_OnStart
<!-- METADATA TYPE=3D"TypeLib" FILE=3D"D:\Program Files\Common
Files\system\ado\msado15.dll" -->
connString =3D "Provider=3DMicrosoft.Jet.OLEDB.4.0;Data
Source=3DC:\WebSites\JobSearch\Profile.mdb"
set cn=3DServer.CreateObject("ADODB.Connection")
cn.Open "driver=3D{Microsoft Access Driver (*.mdb)};dbq=3D" &
connString & ";uid=3D;pwd=3D;"
end sub
</script>
and in my index.asp page I have the following code:
I keep getting the error variable unidentified 'cn' right where I
open my recordset.
Can anyone give me a hint of what to try.
$subst('Email.Unsub').
Message #4 by smassett@s... on Wed, 16 Jan 2002 06:24:24
|
|
Thanks at least I know I'm not lossing my head. What you suggested is what
I started with and when it didn't connect on my recordset I started
surfing. Some of the stuff I read was strange but I tried it. So now I'm
back to square one. with the error
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no default
driver specified
Message #5 by smassett@s... on Fri, 18 Jan 2002 06:15:19
|
|
Solved it. My registry software/ODBC didn't have the security set.
|
|
 |