Question: Excel to Access Table via ASP (Classic/IIS5.1/XP)

Ok im getting this error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E37)
[Microsoft][ODBC Microsoft Access Driver] Could not find output table 'tbl_tickets'.
/database/spreadsheet-import.asp, line 75

From the code below:
==============
Answer Caveat: Im a newbie! So I need to understand (fundamentally) what im doing wrong. So please be kind enough to point out every concern in the code with suggestions and/or recommendations for improvement (and why).
Most appreciated :->

Now the offending code:

<%@LANGUAGE="VBScript"%>
<%
OPTION EXPLICIT
RESPONSE.BUFFER = TRUE

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
 <title>Importing Records from Access into dbase</title>
</head>

<body>
<%
'excel set-up
'==========================
 dim Xpath       'path to excel file
 dim X             'excel connection object
 dim Rx       'excel recordset object
 dim xSql       'sql string to get data from excel spreadsheet

      Xpath       = Server.Mappath("/db/tbl_records.xls")
Set X             = Server.CreateObject("ADODB.CONNECTION")
Set Rx             = Server.CreateObject("ADODB.RECORDSET")


'dbase set-up
'===========================
dim objCon 'db connection string
set objCon = Server.CreateObject( "ADODB.Connection" )
      objCon.OPEN "DSN=dsnProc"
 
'create db command & recordset objects  
'========================================
dim objCmd, objRS
set      objCmd = Server.CreateObject( "ADODB.Command" )
set objCmd.ActiveConnection = objCon
set objRS  = Server.CreateObject( "ADODB.Recordset" )
 

      'Open the connection to the excel spreadsheet
      X.Open "Driver={Microsoft Excel Driver (*.xls)}; " &_
      "DBQ=" & Xpath

      'create SQL string
      xSql = "Select * from [Bus_0001$]"

      Rx.open xSql, X
      Rx.MoveFirst
      
      'create SQL string to insert into database looping through spreadsheet
      'then add each record
      
    Dim sql_Insert
     
     while not Rx.eof
      sql_Insert = "INSERT INTO tbl_tickets " &_
      "(source_name, patron_name, ticket_price, init_deposit, Deposit1, Deposit2, Deposit3, final_balance) " &_
      "VALUES (" &_
      "'" & Rx("source_name").value & "', " &_
      "'" & Rx("patron_name").value & "', " &_
      "" & Rx("ticket_price") & ", " &_
      "" & Rx("init_deposit") & ", " &_
      "" & Rx("Deposit1") & ", " &_
      "" & Rx("Deposit2") & ", " &_
      "" & Rx("Deposit3") & ", " &_
      "" & Rx("final_balance") & ");"
             objCmd.CommandText = sql_Insert
     set objRS = objCmd.Execute       

      'check string: Response.write(objCmd.CommandText & "<br>")
     Rx.moveNext
     Wend

      Rx.Close
Set Rx = NOTHING

      X.Close
Set X = NOTHING

      objRS.CLOSE
set objRS = NOTHING
      
%>
</body>

</html>
the_sleeperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uncle_hoCommented:
If tbl_tickets does not already exist in the mdb, you cannot create it through an INSERT statement.  The easiest solution would be to create an empty table (tbl_tickets) with the appropriate structure in the mdb first.  Alternatively, it could be generated by a SELECT INTO statement or through ADOX (which is an extension of ADO used to manipulate database objects), but that is getting slightly more complicated.  

Also, using the adExecuteNoRecords option for the command object's execute statement will prevent a recordset being returned unnecessarily.  This eliminates some overhead costs.  E.g.:

objCmd.Execute , adExecuteNoRecords
0
the_sleeperAuthor Commented:
Greetings @uncle_ho

  @uncle_ho>>
[1]  If tbl_tickets does not already exist in the mdb, you cannot create it through an INSERT statement.
[2] The easiest solution would be to create an empty table (tbl_tickets) with the appropriate structure in the mdb first.

 1. Yes. tables does exist.
 2. Thats what I did first. by "appropriate structure", i assume you mean each Field in the DB matches a cell in the Spreadsheet. If so. Yes. Table Structure is as follows:

tbl_tickets
-----------
source_id autonum pk
source_name
0
the_sleeperAuthor Commented:
Sorry hit the wrong key...restarting response.

 @uncle_ho [1]  If tbl_tickets does not already exist in the mdb, you cannot create it through an INSERT statement.
 @uncle_ho [2] The easiest solution would be to create an empty table (tbl_tickets) with the appropriate structure in the mdb first.

 1. Yes. tables does exist.
 2. Thats what I did first. by "appropriate structure", i assume you mean each Field in the DB matches a cell in the Spreadsheet. If so. Yes. Table Structure is as follows:

bl_tickets
-----------
source_id          autonum pk
source_name     text
patron_name     text
ticket_price        Currency  
init_deposit        Currency  
Deposit1            Currency  
Deposit2            Currency  
Deposit3            Currency  
final_balance     Currency  

 @uncle_ho [3] Also, using the adExecuteNoRecords option for the command object's execute statement will prevent a recordset being returned unnecessarily.  This eliminates some overhead costs.  

 [3] Ok. Read up on it. Cool. Only problem is...(from code)...

             objCmd.CommandText = sql_Insert
     set objRS = objCmd.Execute, adExecuteNoRecords      

Generates the following error below. Can u provide code example? Thanks.

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/database/spreadsheet-import.asp, line 70, column 26
set objRS = objCmd.Execute, adExecuteNoRecords
-------------------------^

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

uncle_hoCommented:
Can you verify the DSN is setup correctly and is pointing to the right mdb?  It seems to be able to open up the connection without any problems, but if the mdb is present and has the table already in it, I don't know why else you would be receiving that error.

Re: adExecuteNoRecords
You can eliminate the entire left part of the line that calls the Execute command (i.e. take out "set objRS = ").  Since you are not returning any value, you can't use that method call to create a recordset.  I forgot to mention you will probably need to define adExecuteNoRecords at the top of your code:

Const adExecuteNoRecords = 128
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the_sleeperAuthor Commented:
OK, now we're getting somewhere.

1. You were right. Went back and checked my dsn. ....Wrong DSN.   Thanks!
2. Understood on the Const adExecuteNoRecords = 128. Added it to code and works fine. Thanks for the tip!

BUT....Now I get this error:

 "Operation must use an updateable query."

Pointing to this line:  objCmd.Execute, adExecuteNoRecords

Which I modified based on this instruction:

@uncle_ho  >> You can eliminate the entire left part of the line that calls the Execute command
                        (i.e. take out "set objRS = ").

Apparantly, I still dont quite get this. Please explain.
0
uncle_hoCommented:
I think this might be an issue with the permissions on the mdb, or the directory in which the mdb resides.  Check out this MSDN KB article:

http://support.microsoft.com/kb/q175168/

You can also try explicitly setting the mode when you open the connenction object.  I don't think this is causing the error you see, but it's not a bad habit to get into specifying mode anyway:

'Include with other variable definitions
Const adModeReadWrite = 3

'Setting up connection object
dim objCon 'db connection string
set objCon = Server.CreateObject( "ADODB.Connection" )
objCon.Mode = adModeReadWrite     'NEW LINE
objCon.OPEN "DSN=dsnProc"
0
the_sleeperAuthor Commented:
Dude. that was it. Working like a charm now.

Ok... moving all db's to one folder. this is for the birds.

Thanks for your excellent help and patience.

Points coming...
0
uncle_hoCommented:
Glad it worked -- thanks for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.