Did you hear that the ADO.NET 2.0 indexing engine screams? But not in the way I was expecting! [Read more …]
[A DevLife post]
Don’t Forget: www.acehaid.org
Did you hear that the ADO.NET 2.0 indexing engine screams? But not in the way I was expecting! [Read more …]
[A DevLife post]
Don’t Forget: www.acehaid.org
There’s a cool new .net 2.0 feature I didn’t know about until I needed to do this a few days ago. If your application has FullTrust, you can use the System.Data.Sql.SqlDataSourceEnumerator to get a list of available SQL servers (2000 and 2005 only). The query returns a DataTable which you can just attach to a combobox or drop down list.
Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dt As DataTable = instance.GetDataSources()
Remember, though, this requires the assembly to have full trust. There is not a specific permission you can apply to use this otherwise.
Don’t Forget: www.acehaid.org
I went around and around (and dragged poor Sushil Chordia and blogless Leonid Tsybert along for the ride) with an access permission problem that my ASPNET account was having when trying to do SqlDependency.Start. All of the correct permissions (listed below) had been applied to the account, which could be verified with sp_helprotect,NULL,ASPNET
Finally, I just gave up and removed the ASPNET account from SQL Server in its entirety and recreated it with the necessary permissions and everything worked just fine.
Though I’m very frustrated not to have figured out what was causing the problem, I’m satisfied in knowing that there is a solution (remove & recreate.)
Here, as listed in Sushil’s fantastic blog post from late September, which listed all of the RTM changes for Query Notification, is how to set up the perms.Note that this is for IIS5 whereas in IIS6 you would use the NT Authority\NetworkService account.
All of this is run against the database that you want the perms for, not in Master.
sp_grantlogin ‘myMachineName\ASPNET’ –this gives the ASPNET account login access to SQL Server
sp_grantdbaccess ‘MyMachineName\ASPNET’, ASPNET –this gives the login access to the database with the “nickname” ASPNET
GRANT CREATE PROCEDURE to ASPNET
GRANT CREATE QUEUE to ASPNET
GRANT CREATE SERVICE to ASPNET
GRANT REFERENCES on CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to ASPNET –note that the schema is case sensitive!
GRANT VIEW DEFINITION to ASPNET
The above are to call Start(), to do the actual notifications, you need:
EXEC sp_addrole ‘sql_dependency_subscriber’
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO ASPNET
GRANT RECEIVE ON QueryNotificationErrorsQueue TO ASPNET
GRANT REFERENCES on CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to ASPNET
EXEC sp_addrolemember ‘sql_dependency_subscriber’, ‘ASPNET’
GRANT SELECT TO ASPNET
Don’t Forget: www.acehaid.org
Don’t Forget: www.acehaid.org
Don’t Forget: www.acehaid.org
In my Sql Query Notification session, I had an odd problem. My SqlCacheDependency demo did not receive it’s invalidation. This happened when I set it up in code and also when I set it up in <%Cache> directive on the page. This is a demo that I have done many times in the past year so I was not only mystified, but a little heartbroken.
The only thing that was different was that I had run a SqlRequestNotification demo right before it. This demo listens for the notification on a separate thread.
Now playing with it some more, I see that after I end the first demo (SqlRequestNotification) and start up the SqlCacheDependency… when I change the data, I hit the event handler in the first demo. So that was still hanging around.
What I think is happening is that even when I end the demo and close the page, the file based web server is still there (I can even see it in my system tray right now). The app was still alive and the listener was still listening. So now I am going to have to dig further into SqlRequestNotification in a real scenario even though it is not something I think I will not use frequently. If it wasn’t the web app, it is likely that in this non-best practices demo code, I am not disposing enough things (though the listener’s main task is within a using statement) or something along those lines. Most importantly, it is not a likely scenario to run these two things back to back and therefore this is an unusual problem that I encountered.
I couldn’t really take the time to think this through in the session and probably wouldn’t have come to this conclusion under the small pressure of the clock ticking and those expectant faces in the audience. So I just had to go with “I promise you this works! This is the right code for you to use…” and move on to wrap up the session.
Posted from BLInk!
The rules for using Query Notification have finally settled after evolving through all of the betas and ctps. Here they are copied and pasted directly from the msdn help files:
Applications that use query notification features need to take into account the following special considerations.
Query notifications only support certain Transact-SQL statements.
First, to support notifications, queries must not contain:
Derived tables.
Rowset functions.
The UNION operator.
Subqueries.
Outer or self-joins.
The TOP clause.
The DISTINCT keyword.
A COUNT(*) aggregate.
AVG, MAX, MIN, STDEV, STDEVP, VAR, or VARP aggregates.
User-defined aggregates.
A SUM function that references a nullable expression.
The full-text predicates CONTAINS or FREETEXT.
A COMPUTE or COMPUTE BY clause.
Aggregate expressions if GROUP BY is not specified in a select list. If GROUP BY is specified, the select list must contain a COUNT_BIG(*) expression, and cannot specify HAVING, CUBE, or ROLLUP.
An INTO clause.
Conditions that will preclude results from changing (e.g. WHERE 1=0).
FOR BROWSE (or be running with SET NO_BROWSETABLE ON).
A READPAST locking hint.
Second, queries must not reference:
Temporal tables or table variables.
Tables or views from other databases or servers.
Any other views or table-valued functions.
Any system tables or views.
Any nondeterministic function, including ranking and windowing functions.
Any server global variables.
Any Service Broker queue.
Synonyms.
Finally, queries must reference a base table or view.
An application that uses Query Notifications must take into consideration cases where a notification occurs immediately. When data is changed on the server, a notification message will be sent to the appropriate Service Broker queue. Applications need to reregister to receive additional notifications. Therefore, if a data set is updated quickly by multiple applications, an application could receive a notification, retrieve the data, and then get another update notification almost immediately after the cache has been refreshed. Applications that use Query Notifications must be written to take this case into account. If an application uses data that is constantly updated, another strategy for caching data may be more appropriate.
If multiple modifications are made to a set of data with a registered notification request, and those changes occur within a transaction, only a single notification event will be sent.
An application will not receive notifications from an instance of SQL Server that uses the Local System account as the service account.
Posted from BLInk!
Don’t Forget: www.acehaid.org
If you are doing an UpdateBatch with ADO.NET 2.0 and do not explicitly set an UpdateBatchSize parameter, this will default at one – meaning that one row will be sent at a time to the server for updating. Whatever other number you set it at is the number of rows that will be sent in a batch and of course you need to consider a variety of factors when choosing this number (such as network latency, how many columns are in the table, etc – bigger is not always better!) This is hardly new info at this point, but there is one other setting – zero. I am listening to Pablo Castro’s ADO.NET 2.0/SQL Server integration talk from TechEd (DAT320) and laughing because he says (this is not a direct quote – I am paraphrasing) “If you set it to zero, there will be no limit to the number of rows….[pause]…which isn’t really very good for performance .. [pause].. I don’t really know why we put it there, but…[you can practially hear him shrug his shoulders] .. we did”. Pablo can totally get away with this… the audience laughs with him and he moves on. Funny how if some other teams said something like this this, they would probably have many detractors. ADO.NET is just a happy API!
Don’t Forget: www.acehaid.org
Don’t Forget: www.acehaid.org