但畢竟沒辦法一次就到位,如果你真的能夠一次就寫好,完全不用Debug。
可以讓我拜你為師嗎orz
以下是修改CLR的方式、CLR連接本機資料庫,CLR Tcpclient連線。
1.先將原先的trigger 以及 assembly 刪除。
drop trigger pasteUpdate
drop assembly pasteTrigger
需先刪除trigger才能刪除 assembly。
刪除後,重新建立。
Create ASSEMBLY pasteTrigger From 'D:\SqlCLR\KP2spcCLR.dll' with permission_set = external_access
CREATE TRIGGER pasteUpdate
ON pasteConfig
FOR UPDATE
AS
EXTERNAL NAME pasteTrigger.Triggers.pasteTrigger
GO
金鑰不需要重新建立。
2.如果在sql clr裡面要連線到本身的資料庫去讀取資料,
可使用 context connection=true ,直接連本身。MSDN
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
conn.Open();
SqlCommand sqlComm = new SqlCommand();
sqlComm.Connection = conn;
sqlComm.CommandText = "SELECT sn from INSERTED";
sn = sqlComm.ExecuteScalar().ToString();
}
3. 在上一篇有提到,external_access 可以連接socket,但我測出來的結果是沒法跑,需用到unsafe才能使用。我是使用tcpClient的方式要直接連到,自己寫的server上。主程式
Thread socket = new Thread(new ParameterizedThreadStart(RunSocket));
socket.IsBackground = true;
& nbsp; socket.Start(sn);
兩個function private static void RunSocket(object Sn)
{
string CommandSn = "Paste," + (string)Sn;
string IP = "127.0.0.1";
int port = 100;
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(IP, port);
tcpClient.NoDelay = false;
NetworkStream netStream = tcpClient.GetStream();
string output = "";
WriteCommand(netStream, CommandSn);
tcpClient.Close();
}
private static void WriteCommand(NetworkStream netStream, string write)
{
if (netStream.CanWrite)
{
byte[] writeData = Encoding.ASCII.GetBytes(write);
netStream.Write(writeData, 0, writeData.Length);
}
}
0 意見:
張貼留言