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