473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

500.100 Error Passing Session Variable to SQL

I am getting the following error when I run my page I just created. The
first time I run the page I get this error, if I run the page a second time
I get no error and everything works fine. This is the case everytime.

The error is:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type
varchar to numeric.
/business_advice_main/security/login_success.asp, line 65
The code that is running is as follows (line 65 is the last line where the
insert command is executed).

<%
Session("svUserID") =
(RS_UserID_Check.Fields.Item("SECURITY_User_ID").V alue)
%>

<%
set Audit_Login = Server.CreateObject("ADODB.Command")
Audit_Login.ActiveConnection = MM_Business_Advice_STRING
Audit_Login.CommandText = "INSERT INTO dbo.SYS_Login_History (LOGIN_User_ID)
VALUES ('" + Replace(Audit_Login__varUserID, "'", "''") + "' ) "
Audit_Login.CommandType = 1
Audit_Login.CommandTimeout = 0
Audit_Login.Prepared = true
Audit_Login.Execute()
%>
Jul 19 '05 #1
2 2103
I just solved this problem. Don't anyone worry about it.

I had the variable declaration physically in the wrong place in the code.

Thanks

"Keith" <@.> wrote in message news:uW**************@TK2MSFTNGP10.phx.gbl...
I am getting the following error when I run my page I just created. The
first time I run the page I get this error, if I run the page a second time I get no error and everything works fine. This is the case everytime.

The error is:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type
varchar to numeric.
/business_advice_main/security/login_success.asp, line 65
The code that is running is as follows (line 65 is the last line where the
insert command is executed).

<%
Session("svUserID") =
(RS_UserID_Check.Fields.Item("SECURITY_User_ID").V alue)
%>

<%
set Audit_Login = Server.CreateObject("ADODB.Command")
Audit_Login.ActiveConnection = MM_Business_Advice_STRING
Audit_Login.CommandText = "INSERT INTO dbo.SYS_Login_History (LOGIN_User_ID) VALUES ('" + Replace(Audit_Login__varUserID, "'", "''") + "' ) "
Audit_Login.CommandType = 1
Audit_Login.CommandTimeout = 0
Audit_Login.Prepared = true
Audit_Login.Execute()
%>

Jul 19 '05 #2
Keith wrote:
I am getting the following error when I run my page I just created.
The first time I run the page I get this error, if I run the page a
second time I get no error and everything works fine. This is the
case everytime.

The error is:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC SQL Server Driver][SQL Server]
The OLE DB Provider for ODBC Drivers has been deprecated. Instead, you you
should use the native oledb provider for sql server: SQLOLEDB. Your
connection string should look something like this:

sConn = "Provider=SQLOLEDB;" & _
"Data Source = your_server;" & _
"User ID = xxxxxxx;" & _
"Password=xxxxxxx"
Error converting data
type varchar to numeric.
/business_advice_main/security/login_success.asp, line 65
The code that is running is as follows (line 65 is the last line
where the insert command is executed).

<%
Session("svUserID") =
(RS_UserID_Check.Fields.Item("SECURITY_User_ID").V alue)
%>

<%
set Audit_Login = Server.CreateObject("ADODB.Command")
Audit_Login.ActiveConnection = MM_Business_Advice_STRING
Audit_Login.CommandText = "INSERT INTO dbo.SYS_Login_History
(LOGIN_User_ID) VALUES ('" + Replace(Audit_Login__varUserID, "'",
"''") + "' ) "
You should use "&" for string concatenation.
Audit_Login.CommandType = 1
Audit_Login.CommandTimeout = 0
Audit_Login.Prepared = true
Audit_Login.Execute()
%>


You are going to too much trouble here. You do not need to use an explicit
command object. Instead, use a connection object:

Dim cn, sSQL
Set cn = Server.CreateObject("ADODB.Connection")
cn.open MM_Business_Advice_STRING
sSQL= "INSERT INTO dbo.SYS_Login_History " & _
"(LOGIN_User_ID) VALUES ('" & _
Replace(Audit_Login__varUserID, "'","''") & "' ) "

'for debugging:
Response.write sSQL
'comment out the above line when debugging is complete

cn.Execute sSQL,,129
'129 is the result of adding two options:
'1 (adCmdText) and 128 (adExecuteNoRecords)
'Always tell ADO when you are not expecting records so
'it does not create a recordset behind the scenes

So, when you run this, you need to check the result of "response.write sSQL"
when the error occurs and make sure it contains what you expect it to
contain.

HTH,
Bob Barrows
PS. It is not a good idea to use dynamic sql. If you have not heard of SQL
Injection attacks, give the SQL Injection FAQ at www.sqlsecurity.com a read.
You should know that escaping the single quote is not a foolproof means of
preventing sql injection. Using parameterized stored procedures is the
safest approach.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
14
by: Antoni | last post by:
Hello, I wondered if anyone could offer some guidance over my php script. I was hoping the example would allow the user to click the submit buttons and the item number increment. And when the...
2
by: Kurt Hill | last post by:
I am looking for a way to pass error information back from a COM+ object that is "better" than incliding a byref argument in every single function... The session object would be ideal, except for...
4
by: A Web Master | last post by:
I want to know the best way of passing on variable contents on a site coded in ASP using frameset/frame. Content is used in all frames for stuffs like screen_resolution, language, ... My...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
2
by: Roy | last post by:
Hey all, Is it possible to pass session variables between pages in separate projects? For example: inetpub\thisproject\blah.aspx has a session variable and response.redirects the user to...
1
SHOverine
by: SHOverine | last post by:
Recently my web host decided to "upgrade". This change rendered many of my pages useless and I am scrambling to fix the issues, so you may see several posts from me in the coming days. My first...
5
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.