I am attempting to create a CLR Trigger that alters a column value to upper case. But when I try to build the file I get the following:
Severity Code Description Project File Line Suppression State
Error SQL71501: Trigger: [dbo].[UpperTrigger] has an unresolved reference to object [dbo].[tblAirline]. TravelSight \\mac\home\documents\visual studio 2015\Projects\TravelSight\TravelSight\obj\Debug\TRAVELSIGHT.generated.sql 33
My clr code is as follows:
using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
public partial class Triggers
{
// Enter existing table or view for the target and uncomment the attribute line
[Microsoft.SqlServer.Server.SqlTrigger(Name = "UpperTrigger", Target = "[dbo].[tblAirline]", Event = "AFTER INSERT, UPDATE")]
public static void UpperTrigger ()
{
// Open connection for context
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Context Connection=true";
// Create command object
SqlCommand command = new SqlCommand();
command.Connection = conn;
// Create string that defines sql statement
string sql =
"Update tblAirline " +
"SET AirlineName = UPPER(AirlineName) " +
"WHERE AirlineID IN(SELECT AirlineID FROM Inserted)";
command.CommandText = sql;
// Exec command object
command.ExecuteNonQuery();
// Close connection object
conn.Close();
}
}
What have I missed out here?