简体   繁体   English

[SQL Server]不允许从数据类型nvarchar(max)到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询

[英][SQL Server]Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query

That is my code 那是我的代码

DB::statement(DB::raw('EXECUTE dbo.SP_WS_CUST_MAIN ?,?,?,?,?,?,?'),
    [ $USER_ID, $CUST_PYMT_MTHD, $CUST_CMMNT, $CUST_NAME, $ANDROID_LOCATION,
      DB::raw("CONVERT(VARBINARY(MAX), $value)") , $WEEKDAY]
);

How can convert nvarchar(max) to varbinary(max)? 如何将nvarchar(max)转换为varbinary(max)?

I can think of three possibilities. 我可以想到三种可能性。 The simplest would be to create a shell stored procedure (say dbo.SP_WS_CUST_MAIN_VC ) that simply accepts the parameters, including $value as a varchar(max), then does the conversion of $value to a varbinary(max) and calls the target stored procedure. 最简单的方法是创建一个外壳存储过程(例如dbo.SP_WS_CUST_MAIN_VC ),该过程简单地接受参数,包括将$value用作varchar(max),然后将$value转换为varbinary(max)并调用存储的目标程序。 This ensures proper quoting with the parameter replacement. 这样可以确保在参数替换中引用正确。

The second (and most hazardous) is to embed the CONVERT into the parameters directly, opening yourself to all sorts of SQL Injection ugliness. 第二种方法(也是最危险的方法)是将CONVERT直接嵌入参数中,从而使您容易遭受各种SQL注入的麻烦。

The third would be to create a UDF that accepts a varchar(max) and returns a varbinary(max) , and embed that into the base EXECUTE call, eg: 第三个是创建一个接受varchar(max)并返回varbinary(max)的UDF,并将其嵌入到基本EXECUTE调用中,例如:

DB::statement(DB::raw('EXECUTE dbo.SP_WS_CUST_MAIN ?,?,?,?,?,dbo.castAsVarbinary(?),?'),
    [ $USER_ID, $CUST_PYMT_MTHD, $CUST_CMMNT, $CUST_NAME, $ANDROID_LOCATION,
      DB::raw("CONVERT(VARBINARY(MAX), $value)") , $WEEKDAY]
);

Any of these would work, but (1) and (3) should also be secure. 这些方法都可以使用,但是(1)和(3)也应该是安全的。

暂无
暂无

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

相关问题 不允许从数据类型varchar(max)隐式转换为varbinary(max)。 使用CONVERT函数运行此查询 - Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query 错误:不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - Error : Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query OPENROWSET-不允许从数据类型varchar隐式转换为varbinary(max)。 使用CONVERT函数运行此查询 - OPENROWSET - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query 不允许从数据类型sql_variant隐式转换为varbinary(max)。 使用CONVERT函数运行此查询。 ASP.NET SQL数据源 - Implicit conversion from data type sql_variant to varbinary(max) is not allowed. Use the CONVERT function to run this query. ASP.NET SQL DataSource 不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT INSERT查询错误:不允许从数据类型varchar到varbinary的隐式转换。 使用CONVERT函数运行此查询。 - INSERT query error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. Sql异常:不允许从数据类型datetime到int的隐式转换。 使用CONVERT函数运行此查询 - Sql Exception : Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query 不允许从数据类型 sql_variant 隐式转换为 uniqueidentifier。 使用 CONVERT 函数运行此查询 - Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query 获取错误不允许从数据类型datetime到int的隐式转换。 使用CONVERT函数运行此查询。 在sql server中 - getting error Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query. in sql server 不允许从数据类型datetime到int的隐式转换错误。 使用CONVERT函数运行此查询 - Error of Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM