简体   繁体   English

Microsoft OLE DB提供程序的SQL Server错误'80040e14'

[英]Microsoft OLE DB Provider for SQL Server error '80040e14'

Stored procedure, and using ADO to connect, i'm having problems with the quotes however.. 存储过程,并使用ADO进行连接,但是引号有问题。

    x = "text'"

    If instr(x,"'") then x=replace(x,"'","''")

    'x = "text''" at this point

    Set Rs = Server.Createobject("adodb.recordset")
    Rs.Open "Select_SP @name='" & x & "'"

I thought i was doing this right.. But I guess not, because i'm getting this error: 我以为我做对了。。但是我想不是,因为我遇到了这个错误:

    Microsoft OLE DB Provider for SQL Server  error '80040e14' 
    SELECT ID from Table where Name='text''

Shouldn't it be 不是吗

Name = 'text''' 名称='文字'''

Why isn't SQL recognizing the double quotes using ADO? 为什么SQL无法使用ADO识别双引号?

The Select_SP Uses something like this: Select_SP使用如下所示的内容:

     SET @sql = 'SELECT ID from Table where Name='''+@name+''''
     Exec(@sql)

Do I have this SP written correctly? 我是否正确编写了此SP?

The short answer is, don't call procedures the way you're doing it. 简短的答案是,不要以您的方式调用过程。 Use a Command instead. 请改用Command This is from memory, since I don't have a Windows system in front of me at the moment, but it should work: 这是从内存中获取的,因为目前我还没有Windows系统,但是它应该可以工作:

Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
Set Cmd.ActiveConnection = myConnectionVariableHere
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Select_SP"

'Note: if the above two lines don't work, replace them with the following
'cmd.CommandType = adCmdText
'cmd.CommandText = "Select_CP @name=?"

cmd.Parameters.Append cmd.CreateParameter("name", adVarChar, adParamInput, len(x), x)
Rs.Open cmd

Now, all that said, I can't tell you why your procedure is giving that particular output since you're not showing us the code for it. 现在,所有这些,我不能告诉您为什么您的过程为什么要提供特定的输出,因为您没有向我们显示其代码。 But I'm fairly certain ADO isn't going to convert a pair of single quotes into a double quote - not sure why you'd expect it to. 但是我相当确定ADO不会将一对单引号转换为双引号-不知道为什么会这样。

Edit after seeing the OP's edit. 看到OP的编辑后进行编辑。 Don't execute SQL that way unless you absolutely have to. 除非绝对必要,否则不要以这种方式执行SQL。 You will only give yourself grief. 你只会给自己悲伤。 I don't know what database you're using and that procedure syntax doesn't look familiar, but in Oracle you could write something like: 我不知道您正在使用哪个数据库,并且该过程的语法看起来并不熟悉,但是在Oracle中,您可以编写如下内容:

PROCEDURE sql_test(MyName IN VARCHAR2, MyCursor OUT SYS_REFCURSOR) IS
BEGIN
  OPEN MyCursor FOR SELECT id FROM some_table WHERE name = MyName;
END;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server的Microsoft OLE DB提供程序错误'80040e14'无效的列名。 SQL查询 - Microsoft OLE DB Provider for SQL Server error '80040e14' Invalid column name . SQL query 用于SQL Server的Microsoft OLE DB提供程序错误“80040e14”'='附近的语法不正确 - Microsoft OLE DB Provider for SQL Server error '80040e14' Incorrect syntax near '=' Microsoft OLE DB提供程序的SQL Server错误'80040e14'找不到存储的过程 - Microsoft OLE DB Provider for SQL Server error '80040e14' Could not find stored procedure SQL Server错误'80040e14'列名不明确 - SQL Server error '80040e14' Ambiguous column name Microsoft OLE DB提供程序的SQL Server错误'80040e09' - Microsoft OLE DB Provider for SQL Server error '80040e09' Microsoft OLE DB提供程序的SQL Server错误'80040e07' - Microsoft OLE DB Provider for SQL Server error '80040e07' SQL Server 2012 上的 SQL Server 错误“80040e14”语法不正确 - SQL Server error '80040e14' incorrect syntax on SQL Server 2012 尝试从 SQL Server 检索数据时出现 VBA ADODB 错误 (80040e14) - VBA ADODB error (80040e14) when trying to retrieve data from SQL Server SQL Server错误80040e14在结果集中使用经典ASP - SQL Server error 80040e14 Using Classic ASP in a Result Set 无法使用VBA连接到SQL Server(运行时错误(80040e14)) - Cannot connect to sql server with VBA (Run-time error (80040e14))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM