in my include folder I have the file SqlOperations.asp
<%
Option Explicit
Function CheckSqlConnection()
Dim sqlConnection, connString
connString = "Provider=SQLOLEDB.1;Persist Security Info=False; uid=sa; pwd=123456789;Initial Catalog=UserDatabase;Data Source=lakpa-pc"
Err.Clear
On Error Resume Next
SET sqlConnection = Server.CreateObject("ADODB.Connection")
sqlConnection.Open connString
If Err.Number <> 0 Then
CheckSqlConnection = false
End If
CheckSqlConnection = sqlConnection
On Error Goto 0
End Function
Function ExecuteNonQuery(sqlQuery)
Dim checkSql, sqlCmd
checkSql = CheckSqlConnection
If checkSql == False Then
Response.Write("Please check your connection string <br/>" & vbCrlf)
Response.End
ExecutenonQuery = False
Exit Function
End If
checkSql.Execute(sqlQuery)
ExecuteNonQuery = True
End Function
%>
then when I call it from UserInformation.asp which is in root folder
<!--#include file="include/SqlOperations.asp" -->
<%
OPTION EXPLICIT
dim fName, mName, lName,age,address,postCode,telephone, queryVal
fName = Request.Form("fName")
mName = Request.Form("mName")
lName = Request.Form("lName")
age = Request.Form("age")
address= Request.Form("address")
postCode = Request.Form("postCode")
telephone = Request.Form("telephone")
if fName <>"" then
queryVal = "INSERT INTO UserInfo(FirstName, MiddleName, LastName, age, Address, PostCode, Telephone) VALUES('" + fName +"','" + mName+"','" + lName+"','" + age +"','" + address +"','" + postCode +"','" + telephone +"')"
ExecuteNonQuery queryVal
end if
%>
The Debug isn’t working. But If I remove the include line then the debug works and I get the error
Microsoft VBScript runtime error: Variable is undefined: 'ExecuteNonQuery
I just don’t understand it. I am new to ASP classic. Can any one tell me the reason why its happening.
Well the problem was the syntax, I was confused. I used “If checkSql == False Then”, the syntax was wrong it should have only one “=” sign. Well I modified little bit of it and now its working fine. This is for connecting ASP Classic with MSSQL. May be it will be helpful to somebody.
Thanks Kane for the reply 🙂