Wrox Programmer Forums
|
ASP CDO As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP CDO section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2004, 01:12 PM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to stellabantug
Default

OK...I'm getting this message:

Connection is
SQL is INSERT INTO ResearchInfo (Name,Site,ReqEmail,VPEmail,Priority,DateNeeded,Pr ospectName,ConsID,Add,ProspPhone,PastGiving,Advoca teContactName,ContactTitle,ContactPhone,AdvocateRe lationship,ResearchNeededFor,MMStatus,Questions,Ot herInfo,SuggestedResources) VALUES ('testing','testing','stella.bantug','','Low','03/20/2004','testing','','','','Yes','','','','','Prelim inary Evaluation','Identification','testing','','')


 
Old March 17th, 2004, 01:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, so your connection is empty.

Apparently,

Application("SampDatabConn_ConnectionString")

does not contain a valid connection. Check your global.asa file for the connection string.
Alternatively, assign a valid connection string (or a DSN name) to myConnString

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 17th, 2004, 01:27 PM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to stellabantug
Default

THANKS IMAR!!!

One last thing... how do I check the global.asa file if the connection is valid, and if so, how do I repair this?

This is really odd because the DSN Name is on the System DSN List and the connection is correct as it is listed there.

 
Old March 17th, 2004, 02:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Apparently the person that created this code, stored the connection string in the application object.
This is a common practice, as it allows you to maintain the connection string at one location. (Note that storing the connection string is really different from storing the connection itself in application state. You should create, open, close and destroy a connection on each page that requires one, and never store it in the application state).
Alternatively, you can store the connection in a file and include that file in other pages. IMO, that's a better solution as it allows you to change the connection without restarting the application.

To store and use the string, use the Application_OnStart event defined in the global.asa file. for example:

Sub ApplicationOnStart()
  Application("MyConnectionString") = "Your Connection String Here"
End Sub

Now, in other pages you can use Application("MyConnectionString") as your connection string, for example:

MyConnection.Open Application("MyConnectionString")

How "Your Connection String Here" should exactly look depends on your system and database. Look here for examples.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 17th, 2004, 02:42 PM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to stellabantug
Default

So should I add this code right after the "set myConnection = Nothing"?

 
Old March 18th, 2004, 05:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Au contraire; that would be about the worst place to put it ;)

The Application variable is also called a Global variable, as it has global scope for the application (that's where the global.asa has its name from). This means it can be read and set from about every page in your Web site.

To understand how this works, consider this:

1. Your application starts up the very first time because someone requests the first page in your application
2. The event Application_OnStart fires (because the application starts, but I guess you figured that out)
3. The line of code in the event runs:
    Application("MyConnectionString") = "Bla bla bla"
4. The value for Application("MyConnectionString") is stored in memory in such a way that other pages can access it as well
5. Other pages can now use this variable by reading its value; no need to include anything, no need for references, etc. All you need to do is this:

MyConnection.Open Application("MyConnectionString")

This will open the connection, with the connection string defined in Application("MyConnectionString")

So, what you should do is this. Locate the global.asa file in the root of your Web application. Open it and locate the Application_OnStart event.
Make sure that Application("MyConnectionString") holds a valid connection string, like "dsn="MyDsn", or better yet, a valid OleDb connectionstring from the site I pointed you to.

Would you mind cutting a few of the %%%%%%% from your previous post? That minimizes the odd scrolling effect in this thread.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 18th, 2004, 11:17 AM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to stellabantug
Default

Hi Imar!

I checked the global.asa file and the DSN is there with the code you specified. But I am still getting the same error message:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/OnlineForm/Email1.asp, line 71


I do not know whatelse to do. HELP!

 
Old March 18th, 2004, 11:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

How does your Application_OnStart look like? Can you post its code?

Somewhere something is going wrong. If the connection string ends up empty (as was demonstrated with the Response.Write statement), it means that somehow the variable is not assigned correctly, or it looses its value.

Is your application folder marked as a Virtual Directory under IIS? Where is the global.asa located, both in terms of physical location (c:\Inetpub.....) as in "virtual location?

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 18th, 2004, 11:52 AM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to stellabantug
Default

Actually, I fired up the ASP page with the code that you gave me before and this is the message I got:

Connection is DSN=SampDatabConn;DRIVER={Microsoft Access Driver (*.mdb)}
SQL is INSERT INTO ResearchInfo (Name,Site,ReqEmail,VPEmail,Priority,DateNeeded,Pr ospectName,ConsID,Add,ProspPhone,PastGiving,Advoca teContactName,ContactTitle,ContactPhone,AdvocateRe lationship,ResearchNeededFor,MMStatus,Questions,Ot herInfo,SuggestedResources) VALUES ('','','','','','','','','','','','','','','','',' ','','','')


As for the Application_ONStart, this is my code:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
    '==FrontPage Generated - startspan==
    Dim FrontPage_UrlVars(5)

'--Project Data Connection
        Application("SampDatabConn_ConnectionString") = "DSN=SampDatabConn;DRIVER={Microsoft Access Driver (*.mdb)}"
        Application("SampDatabConn_ConnectionTimeout") = 15
        Application("SampDatabConn_CommandTimeout") = 30
        Application("SampDatabConn_CursorLocation") = 3
        Application("SampDatabConn_RuntimeUserName") = ""
        Application("SampDatabConn_RuntimePassword") = ""
'--
    Application("FrontPage_UrlVars") = FrontPage_UrlVars
    '==FrontPage Generated - endspan==
End Sub


 
Old March 18th, 2004, 12:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It looks like you're mixing up two type of connection string; a DSN type, and the (older) DRIVER connection string.

Change it to this:

Application("SampDatabConn_ConnectionString") = "DSN=SampDatabConn"

Even better: change it to something like this:

Application("SampDatabConn_ConnectionString") = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & Server.MapPath("/Databases/MyDB.mdb") & _
           "User Id=admin;" & _
           "Password="

In the example above, I am assuming the database is stored in a folder called Databases in the root of your site. Change the path so it fits your situation. Of course this may not be applicable in your situation, so in that case, stick to the DSN.

I am under the impression you're missing a few important Web programming concepts. If I were you, I'd get a good book on this subject. Beginning ASP 3.0 or Beginning Dreamweaver MX (2004) would be ideal books to get a better understanding of the tasks you're currently working on.

Can you please put some line breaks here and there in the stuff you're posting? It makes your post much easier to read.....


Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
CDONTS and CDOSYS hamproof Classic ASP Databases 0 August 24th, 2007 01:37 PM
CDONTS to CDOSYS icis Classic ASP Basics 1 March 2nd, 2006 06:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.