Is it possible to call a web service from SQL Server? - sql

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 :-)

Related

Is there a way to Debug a Store Procedure(SQL server) in real time while running a backend console project?

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 there a way to set ODBC Connection options in a DSN?

My application (a testcase automation tool) does not support calling ODBC's SQLSetStatmentOption. I need to set the cursor option SQL_SOPT_SS_CURSOR_OPTIONS to SQL_CO_FFO_AF. Right now I connect to the server using a connection string (no DSN). I am using sqlsrv32.dll or Sqlncl10.dll.
Is there a way to set the cursor option in a DSN (or other layer) between my tool and the MSSQL server? The tool handles creating the cursor (or results set) and iterating through the result set in a way that seems to obscure any ability to manage it directly. It does allow for calling SQLSetConnectAttr() but as far as I can tell there's no way to set a cursor option in there.
All of this is an attempt to speed up retrieving data over a remote connection. In SQL Management Studio I get comparable response times to the local or remote DB, but in the automation tool the remote queries take hundreds of times longer, probably because it seems to be making a round trip to the sever for every row.
There is no way to set statement options in the connection string that I know of. In ODBC 1.0 and 2.0 you could make calls to SQLSetConnectOption for statement attributes and they set those attributes in each statement created in that connection but a) that is an old version of the API (although it probably still works) b) you still cannot do it from the DSN. In unixODBC you can set some environment and connection attributes in the DSN but your obviously Windows.
I'm not convinced anyway that you've identified the problem correctly and even if you have, how do you know your app does not use SQLGetData (which is disabled when you set SQL_CO_FFO_AF). Are you sure you've not enabled MARs. Did you try getting an ODBC trace to see what the app is doing?

TSQL memory related queries

I need to find if /3GB switch and /PAE is enabled on a server.
Also, I want to know the size of page file and physical RAM on the server.
I can check them manually but how can I check them using TSQL on both SQL 2000 and SQL 2005?
Use WMI:
The Win32_OperatingSystem class exposes the PAEEnabled property
The Win32_ComputerSystem class exposes the SystemStartupOptions property that contains the boot.ini parameters (pre-Vista)
Post Vista you need to use the Boot Configuration Data WMI Provider to see if /3gb is enabled, but I'm not sure how.
To run WMI queries, use ExecuteWQL from the Policy Based Management framework (which you should be using anyway for the audit task you describe, see Administering Servers by Using Policy-Based Management).
PowerShell can also read WMI. Ultimately, WQL queries can be run straight from T-SQL using sp_OACreate and friends.
this looks like one http://sugeshkr.blogspot.com/2007/12/check-if-3gb-is-configured-or-not.html
If(Select Virtual_Memory_In_Bytes/1024/(2048*1024) from Sys.dm_os_Sys_Info) < 1
Begin
PRINT '/3GB Switch Not Configured in Boot.Ini (CHECK)'
End

How to Inspect ODBC communication, to see the SQL being passed through?

Is there a tool for windows that we can use to inspect any SQL commands that go through a particular ODBC data source?
You can make ODBC log out everything it's doing:
http://support.microsoft.com/kb/274551
http://msdn.microsoft.com/en-us/library/ms711020%28VS.85%29.aspx
You can also do it programmatically:
... One can do this by calling SQLSetConnectAttr and set the SQL_ATTR_TRACE attribute in the connection to SQL_OPT_TRACE_ON. So, by doing this you would be enabling/disabling it for the connection duration.
http://decipherinfosys.wordpress.com/2009/01/17/odbc-tracing/
If you're using SQL Server, look at the SQL Server Profiler. Profiler allows you to monitor/trace all communications between your application and the SQL Server, including which procedures are called, parameter values, etc, without having to modify your application.
If you're using a different server, you should be able to find a sql proxy that will do the same thing.

Tools to Replay Load on a SQL Server

Has anyone come across any good tools (preferably but not necessarily FOSS) that can read a SQL Server (2005/2008) trace file and execute the commands against another database. We are attempting to perform some performance testing on our SQL servers and would like to replicate an actual load.
I have come across but not yet used:
JMeter
ReplayML
Preferably, the application would be able to use threading to mimic user connections and query execution on the SQL Server.
You can replay a SQL Server Profiler trace against another server using the SQL Server Profiler itself.
See the following Microsoft Reference as a starting point.
http://msdn.microsoft.com/en-us/library/ms189604.aspx
Quest Software also have a tool called Benchmark Factory that can be used to perform SQL Server load testing.
http://www.quest.com/benchmark-factory/
One of the best tools is actually freely available from Microsoft. The RML Utilities are targeted at SQL2005 & SQL2008 and are specifically designed for this type of testing.
You can download the tools from http://www.microsoft.com/downloads/details.aspx?FamilyId=7EDFA95A-A32F-440F-A3A8-5160C8DBE926&displaylang=en
We have used them to solve several performance and locking issues.
Note: Capturing trace files using the SQL Profiler GUI can add to performance problems due to the way the GUI and Trace backend interact. The RML Utilites include a script that can capture traces directly from the SQL Server without using the GUI.
You can replay trace files directly in SQL Profiler, although I've only used it a couple of times for that, so I don't know what all of the limitations are on it.
team system has an add-on that you can find on codeplex: It is called ->
sql load test
Let me know if that works well for you.
I know this is a really old question but after searching for some time i discovered a new open source tool.
https://github.com/spaghettidba/WorkloadTools which works great