Hi I am working on making a CLR stored procedure using C#, for which I am learning through examples.
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
A .NET Framework error occurred during execution of user defined routine or aggregate ‘GetProductsByPrice’:
System.Data.SqlClient.SqlException: The locale identifier (LCID) 16393 is not supported by SQL Server.
System.Data.SqlClient.SqlException:
at Microsoft.SqlServer.Server.SmiEventSink_Default.DispatchMessages(Boolean ignoreNonFatalMessages)
at Microsoft.SqlServer.Server.SqlPipe.SendResultsStart(SqlDataRecord record)
at StoredProcedures.GetProductsByPrice(Int32 price)
User transaction, if any, will be rolled back.
I am referring to this msdn article for the code.
Please help me out on this.
The exception states:
The locale identifier (LCID) 16393 is not supported by SQLThe SqlMetaData.LocaleId property contains the locale ID of the column or parameter where the default value is the current locale of the current thread.
The default value in this your case
16393which is theEnglish - Indialocale (see table) but it seems your SQL server was installed with a different localeEnglish - United StatesSo you have three options:
English - IndiaSpecify the locale manually when creating the
SqlMetaData:Where the 1033 is the Locale ID of
English - United States