Showing posts with label bol. Show all posts
Showing posts with label bol. Show all posts

Wednesday, March 21, 2012

Script task: Dts.Logging.Log

I am trying to understand the use-case of Dts.Logging.Log.

Following BOL, I see that I can use Dts.Log to send a custom log message to my log provider. The following example code produces an event called "User:ScriptTaskLogEntry", with the message "My custom message here".

Dim dataBytes(0) As Byte

Dts.Log("My custom message here", 0, dataBytes)

I would like to be able to produce my own custom event (lets call it "MyCustomEvent"), as well as a custom log message. I thought it would be possible via Dts.Logging.Log, which requires that I specify an event name, in addition to a log entry. However, when I place the following code in the script task, I do not get any logging whatsoever.

Dim dataBytes(0) As Byte

Dts.Logging.Log("MyCustomEvent", System.Environment.MachineName, System.Environment.UserName, "Custom Log", "", "", "My custom message here", Now, Now, 0, dataBytes)

Any thoughts?

Thanks!

The script task can't log custom message type. The problem is that custom log message needs to be declared by task in advance so that it appears in the Details tab of the Logging window.

Custom task (reusable separately packaged .NET or C++ code, that appears on toolbox just like any Microsoft task) can do it, but this functionality is not available in Script task.sql

Tuesday, February 21, 2012

scope_identity and sessions

I found in bol that I can use scope_identity to get the last identity in a specific session and for a the current scope. Now what I would like to know is what is a session? We usually create one user for our software in the database and create an application users table. This means that all users actually connect as the same database user to the database. Does SQL Server see this as different sessions or just one?True what you have mentioned above sessions, check with BOL for sessions then.|||Even if you log in using same username, you can open multiple sessions, like in Query Analyzer.