I am building an angularjs .net application with WebApi2 and SQL Server 2008.When page loads, it sends multiple ajax calls to WebApi. WebApi then in turn passes on these calls to Sql server, but when I look into sql profiler, all calls to db are executed with same SPID,which I believe is a sequential execution rather than parallel execution of stored procs.
Even after having looking at the network monitor tab on firefox browser, all these calls return one after another and not at the same time.This might create bottleneck in the system , as angular sends parallel request to webapi but sql server is executing each request sequentially rather than parallel.
I have used Data Access Application Block v6.0 and have put Connection and Command objects under "Using" scope. Still it fires all my storedproc with same SPID. Is there anything which I am doing wrong here?
Related
I'm trying to find a bug on a store procedure(SQL server) that gets executed from a console application coded in C#. Is there a way I can do some sort of breakpoints into the Store Procedure scripts and find how the data gets processed into the store procedure in real-time?
I know that you can debug a simply Stored procedure on Visual Studio. But what I want to do it's to debug it in real-time with the console application.
Dependent on which version of SQL Server you are using you will want to use either SQL Server Profiler or Extended Events, see Quick Start: Extended events in SQL Server and SSMS XEvent Profiler.
Is it possible to register a C# callback function in ODP.net, so that it is called before each query is sent to the Oracle database?
The purpose is to run sanity checks on the query (SQL injections) and block it if we find risks.
Google only tells me about change notification callbacks, which are completely different.
Is it somehow possible to call a web service from SQL Server without using CLR and get response immediatly back(not powershell, etc..)?
SQL Server provide a lot of different options to execute external scripts or connect to other devices. SQLCLR is one of the best but not the only option
From SQL 2016 you can use R or you can use Python, which let basically do what ever you want if you have permission.
You can use xp_cmdshell to execute commands
You can use OLE Automation objects (here is a nice sample).
You can use auditing tools (not recommended for most of these cases since these run in the background and not only when you need them), which allow you to execute external scripts on event
You can use simple QUEUE in the server side. In the Sp you can simply add message to the QUEUE and using external service app you can execute anything that you want once a new message get to the QUEUE. This option can be very useful since the execution is done asynchronous.
I can probably think about a lot more options... but let's start with these :-)
I am checking one SSIS job execution report, which shows me the below report:
The most recent one succeeded, but when you take a look at ID:217583, it is still running and never finished (duration keeps increasing), and when I check the job activity in sql server agent, that execution should failed before, the reason why I said that was because the start time matched. Here is the job history in sql server agent :
So I assume this job execution failed but for some mystery reason, it still shows (or running) in the background with 'running ' status.
Does anybody have any ideas? I tried to EXEC msdb..sp.stop_jobscommand, but cannot locate that job ID.
Can anybody tell me what was really happened? Is this job still running somewhere else? If so, how to locate that job execution and stop it? Or how to let the report does not show this weird record anymore?
Thx in advance :)
If your are executing this package as a job from the SSISDB, you can use the stop operation procedure as follows.
USE SSISDB
GO
EXEC [catalog].[stop_operation] 217583
https://msdn.microsoft.com/en-us/library/hh213131.aspx here is a reference to stopping operations. In case this link breaks, ...
The SSISDB database stores execution history in internal tables that are not visible to users. However it exposes the information that you need through public views that you can query. It also provides stored procedures that you can call to perform common tasks related to packages.
Typically you manage Integration Services objects on the server in SQL Server Management Studio. However you can also query the database views and call the stored procedures directly, or write custom code that calls the managed API. SQL Server Management Studio and the managed API query the views and call the stored procedures to perform many of their tasks. For example, you can view the list of Integration Services packages that are currently running on the server, and request packages to stop if you have to.
Viewing the List of Running Packages
You can view the list of packages that are currently running on the server in the Active Operations dialog box. For more information, see Active Operations Dialog Box.
For information about the other methods that you can use to view the list of running packages, see the following topics.
Transact-SQL access
To view the list of packages that are running on the server, query the view, catalog.executions (SSISDB Database) for packages that have a status of 2.
Programmatic access through the managed API
See the Microsoft.SqlServer.Management.IntegrationServices namespace and its classes.
Stopping a Running Package
You can request a running package to stop in the Active Operations dialog box. For more information, see Active Operations Dialog Box.
For information about the other methods that you can use to stop a running package, see the following topics.
Transact-SQL access
To stop a package that is running on the server, call the stored procedure, catalog.stop_operation (SSISDB Database).
Programmatic access through the managed API
See the Microsoft.SqlServer.Management.IntegrationServices namespace and its classes.
Viewing the History of Packages That Have Run
To view the history of packages that have run in Management Studio, use the All Executions report. For more information on the All Executions report and other standard reports, see Reports for the Integration Services Server.
For information about the other methods that you can use to view the history of running packages, see the following topics.
Transact-SQL access
To view information about packages that have run, query the view, catalog.executions (SSISDB Database).
Programmatic access through the managed API
See the Microsoft.SqlServer.Management.IntegrationServices namespace and its classes.
To keep things simple, here is an example of what I am trying to do:
My CLR Library written in C# (it is thread-safe even though I don't show it in the example):
public static class MySP {
private static Session _session;
[Microsoft.SqlServer.Server.SqlProcedure]
[SqlFunction]
public static void Send(string destination, string message)
{
if(_session == null)
_session = new Session();
_session.SendMessage(destination, message);
}
}
Once compiled, I import it into my SQL Server (using Microsoft SQL Server Management Studio):
CREATE ASSEMBLY [MyDLL] FROM 'C:\MyDLL.dll' WITH PERMISSION_SET = UNSAFE;
GO
I import the Stored Procedure:
CREATE PROCEDURE sp_Send (#DestinationName nvarchar(256), #MessageString nvarchar(max))
AS EXTERNAL NAME MyDLL.[NS.MySP].Send
GO
Finally, I have a SQL script that calls the Stored Procedure:
EXEC sp_Send "MyDestination","MyMessage"
GO
Now the problem:
Every time I call the Stored Procedure (as shown just above), a new Session object is created (I know, because I see multiple TCP connections open on the other side).
How do I stop the SQL Server from loading my library multiple so that it actually enforces the "static" object paradigm? I only want I single "Session" to be created, until the process of the SQL Server dies, not one static object every time the Stored Procedure is called.
Thank you.
More details (not sure if they were necessary):
My "Session" object is loaded from another library (so I technically load 2 DLLs, but only showed one in my example above to keep things simple) which in turns wraps (and loads) a native DLL, not sure if this information was relevant but figured I would add it.
Edit:
I would also like to add that if I call my Stored Procedure multiple times in the same SQL script, a single Session object is created. Every time I call that script with multiple Stored Procedure calls, a new Session object is created.
I never programmed a .NET stored procedure, but clearly this happens because the SQL server creates multiple AppDomains (or loads an AppDomain and unloads it after the procedure is done executing). You should be able to see AppDomain activity in the SQL sever log.
From the little I've googled, the SQL server should only load one AppDomain per database. It could be that the code you wrote somehow throws an unhandled exception, which causes the AppDomain to unload (and the server reloads it when the procedure is called again).
It is also possible that the SQL server is under memory pressure, in which case it will unload the AppDomain to save memory.
I don't think you can guarantee just a single Session object within the SQL server, but you can probably minimize the amount of times a new session is created. If you want full control over the session's lifetime, you'll have to host it yourself (perhaps inside a Windows service exposing the session via WCF, and have the SQL server connect to the service in order to interact with the session). As long as SQL server is the host - your session lives by its rules...
(Then again, it could just be that the info I've read is wrong, and SQL server's AppDomain management is done differently)