0
我正在尝试创建一个将列值更改为大写的CLR触发器。 但是当我尝试建立我获取文件如下:CLR触发无法解析的参考错误
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
我的CLR代码如下:
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();
}
}
有什么我错过了吗?
1.为什么使用与tsql触发器相反的CLR触发器? 2.为什么它的上层(sql server不区分大小写)很重要? – Wjdavis5
你是否有这个名字为tblAirline的表,如果是,请尝试使用此tblAirline而不是[dbo]。[tblAirline] – rashfmnb
SQL可以区分大小写 - 这取决于您的归类。点击这里:https://msdn.microsoft.com/en-us/library/ms144250(v=sql.105).aspx – Andez