[英]CLR Stored Procedure with C# throwing errors
Hi I am working on making a CLR stored procedure using C#, for which I am learning through examples. 嗨,我正在使用C#制作CLR存储过程,我将通过示例进行学习。
Below is what I am trying now 以下是我现在正在尝试的
public static void GetProductsByPrice(int price)
{
SqlConnection connection = new SqlConnection("context connection=true");
connection.Open();
string commandText = "SELECT * FROM Products WHERE PRICE < " + price.ToString();
SqlCommand command = new SqlCommand(commandText, connection);
SqlDataReader reader = command.ExecuteReader();
// Create the record and specify the metadata for the columns.
SqlDataRecord record = new SqlDataRecord(
new SqlMetaData("col1", SqlDbType.NVarChar, 100),
new SqlMetaData("col2", SqlDbType.NVarChar, 100));
// Mark the begining of the result-set.
SqlContext.Pipe.SendResultsStart(record);
// Send 10 rows back to the client.
while (reader.Read())
{
// Set values for each column in the row.
record.SetString(0, reader[1].ToString()); //productName
record.SetString(1, reader[2].ToString()); // productDescription
// Send the row back to the client.
SqlContext.Pipe.SendResultsRow(record);
}
// Mark the end of the result-set.
SqlContext.Pipe.SendResultsEnd();
}
But when I try to run it I get the below errors 但是当我尝试运行它时,出现以下错误
Msg 6549, Level 16, State 1, Procedure GetProductsByPrice, Line 0 消息6549,级别16,状态1,过程GetProductsByPrice,第0行
A .NET Framework error occurred during execution of user defined routine or aggregate 'GetProductsByPrice': 在执行用户定义的例程或聚合'GetProductsByPrice'期间发生.NET Framework错误:
System.Data.SqlClient.SqlException: The locale identifier (LCID) 16393 is not supported by SQL Server. System.Data.SqlClient.SqlException:SQL Server不支持区域设置标识符(LCID)16393。
System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException:
at Microsoft.SqlServer.Server.SmiEventSink_Default.DispatchMessages(Boolean ignoreNonFatalMessages) 在Microsoft.SqlServer.Server.SmiEventSink_Default.DispatchMessages(布尔值ignoreNonFatalMessages)
at Microsoft.SqlServer.Server.SqlPipe.SendResultsStart(SqlDataRecord record) 在Microsoft.SqlServer.Server.SqlPipe.SendResultsStart(SqlDataRecord记录)
at StoredProcedures.GetProductsByPrice(Int32 price) 在StoredProcedures.GetProductsByPrice(Int32价格)
User transaction, if any, will be rolled back. 用户事务(如果有)将被回滚。
I am referring to this msdn article for the code. 我指的是此msdn文章中的代码。
Please help me out on this. 请帮助我。
The exception states: The locale identifier (LCID) 16393 is not supported by SQL
异常指出: The locale identifier (LCID) 16393 is not supported by SQL
The SqlMetaData.LocaleId property contains the locale ID of the column or parameter where the default value is the current locale of the current thread. SqlMetaData.LocaleId属性包含列或参数的语言环境ID,其中默认值是当前线程的当前语言环境。
The default value in this your case 16393
which is the English - India
locale ( see table ) but it seems your SQL server was installed with a different locale English - United States
在这种情况下,默认值为16393
,它是English - India
语言环境( 请参见表 ),但是您的SQL Server似乎安装了其他语言环境, English - United States
So you have three options: 因此,您有三种选择:
English - India
配置/重新安装SQL Server以使用语言环境English - India
Specify the locale manually when creating the SqlMetaData
: 创建SqlMetaData
时手动指定语言环境:
SqlDataRecord record = new SqlDataRecord( new SqlMetaData("col1", SqlDbType.NVarChar, 1033, SqlCompareOptions.None), new SqlMetaData("col2", SqlDbType.NVarChar, 1033, SqlCompareOptions.None));
Where the 1033 is the Locale ID of English - United States
其中1033是English - United States
的地区设置ID- English - United States
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.