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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP insert to SQL Server database 1

Status
Not open for further replies.

JGresko

Programmer
Apr 24, 2002
86
US
I'm attempting to insert a record to a SQL Server database from an ASP webpage. I'm having trouble determining the best method to use to do this. My MSDN help files seem to be on vacation because they're not giving me what I need today.

Any pointers will be much appreciated!

Thanks, Judy

When I run the code below I get the following error:


Error#: 424 - Object required
TestFile.doc database insert failed.


'open a database connection
Code:
strDSN = Application("FileExchange_ConnectionString")
 Set conn = Server.CreateObject("ADODB.Connection")    
 conn.Open strDSN
'Create a command object
Code:
Dim cmd
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = conn
cmd.CommandTimeout = 15
cmd.CommandType = adCmdText
'Create the Insert SQL
Code:
tsql = "INSERT INTO FileCheck (id, Path, Document, UserName, CreateDate) VALUES (NEWID(),'" & Dir & "','" & newfilename0 & "','" & session("User") & "', GETDATE())"

cmd.CommandText = tsql
cmd.Execute
'Catch Errors
Code:
if Err <> 0 Then 
     errtext = &quot;Error#: &quot; & err & &quot; - &quot; & err.description
     & &quot;<BR>&quot; & newfilename0 & &quot; database insert failed.&quot;
End If
 
This error is different (same code) than the one you posted in that asp forum...

&quot;TestFile.doc database insert failed. &quot;

The &quot;.doc&quot; indicates that you are not working on the server-side (indicated by &quot;.asp&quot; in this case). Simply try renaming your document &quot;testFile.asp&quot; and make sure that you are calling it through the server (the path in the address bar should not begin with a local drive letter &quot;c:\testFile.asp&quot; - It should be something like : &quot; Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 
mwolf00 Thanks for your help.

I may not have identified my problem specific enough so here's a clarification:

The file isn't being inserted to the database, just a reference to it's location (in string format)

I think the problem is at the cmd.Execute line... the sql that is created works fine if I execute it on it's own (outside ASP)... so this is really an ASP problem, but I hoped someone on this list would have experience executing insert statements via ASP against an SQL Server database.

Just for reference, the insert statement I'm trying to execute is:

INSERT INTO FileCheck
(id, Path, Document, UserName, CreateDate)
VALUES (NEWID(), 'D:\InetPub\ 'TestFile.doc', 'JGresko', GETDATE())
 
Like I said in the .asp forum:

Change
Set cmd = New ADODB.Command
To
SET cmd = server.createobject(&quot;ADODB.command&quot;) Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 

and as I also said in the other forum... that was it [santa3]

Thank You and Happy Holidays
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top