我正在尝试为当前项目实现查询通知。我正在使用SqlNotificationEventArgs
实施查询通知。当我直接在Ado.net命令中为查询内联SQL时,我能够使代码工作,但是,当我在存储过程中放入相同的查询通知时,查询通知似乎不会上班。它在事件args的e.Info
参数中返回Public Sub GetCust(ByVal CustomerId As String)
Dim oConn As SqlConnection
Dim connectionString As string
connectionString = GetConnectionString()
SqlDependency.Stop(connectionString)
SqlDependency.Start(connectionString)
oConn = New SqlConnection(connectionString)
'This is the code for the stored procedure path
'Dim oCommand As New SqlCommand("SelectCustomerInfo", oConn)
'oCommand.CommandType = CommandType.StoredProcedure
'oCommand.Parameters.AddWithValue("@CustomerId", CustomerId)
'This is the code for using inline SQL
Dim strSQL As String
strSQL = "select [CustomerId],[name], [age],[gender],[favorite_food] from dbo.custpreferences where customerid = '" & CustomerId & "'"
Dim oCommand As New SqlCommand(strSQL, oConn)
oCommand.CommandType = CommandType.Text
oCommand.Notification = Nothing
Dim dep As SqlDependency = New SqlDependency(oCommand)
AddHandler dep.OnChange, AddressOf cust_onchange
oConn.Open()
Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter(oCommand)
dataAdapter.Fill(dsCustomers)
If (Not dataAdapter Is Nothing) Then dataAdapter.Dispose()
If Not oConn Is Nothing Then oConn.Dispose()
End Sub
Private Sub cust_onchange(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlNotificationEventArgs)
GetCustInfo(mCustomer.strCustomerID)
Dim dep As SqlDependency = DirectCast(sender, SqlDependency)
RemoveHandler dep.OnChange, AddressOf cust_onchange
End Sub
Query(8)的值。它还继续大火。每隔30秒以上。
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET ARITHABORT ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SelectCustInfo]
@CustomerID VARCHAR(6)
AS
SELECT
[CustomerId], [name], [age], [gender], [favorite_food]
FROM
dbo.CustInfo (NOLOCK)
WHERE
(CustomerId = @CustomerID)
这是存储过程:
{{1}}
为什么这适用于内联SQL与使用存储过程的任何想法?
答案 0 :(得分:0)
一旦我删除了与READ UNCOMMITED相同的NOLOCK提示,我就可以使用它。
答案 1 :(得分:0)
与SqlDependency
一起使用存储过程时
请勿使用