Logging ODBC, SQL Server - sql

How to log, trace or get queries that an application send to Microsoft SQL Server 2008 thru ODBC driver (without modifying application...)
Maybe it can be done with SQL Server itself or ODBC has some query logging?

#davispuh, you can use the SQL Profiler to trace SQL statements.
you can also use the ODBC Tracing.

To Create a Trace using SQL-Profiler:
On the File menu of SQL-Profiler, click New Trace, and connect to an
instance of SQL Server. The Trace Properties dialog box appears.
In the Trace name box, type a name for the trace.
In the Use the template list, select a trace template on which to
base the trace, or select Blank if you do not want to use a template.
If you do not use a template you can hit the Show all Events checbox and choose which events you would like to trace, there you can choose if errors, logins etc are traced. For more information take alook at: Specify Events and Data Columns for a Trace File (SQL Server Profiler) for Example you have a category there Errors and Warnings which include special Error events.
For more information see the documentation
If you need to do this for ODBC you can check the following two topics:
Profile Driver Performance Data (ODBC)
Log Long-Running Queries (ODBC)
Hope this helps.

Related

Best way to debug SQL queries in Acumatica

How can I monitor the SQL queries generated by Acumatica?
You can monitor lots of things such as SQL and Memory through the Request Profiler.
Go to: System-->Management-->Request Profiler
There is a check box to turn on SQL Logging.
Enable Logging + Enable SQL logging then go and do something that causes data to load. Then come back to this screen and click refresh and you will see the actions performed. You can select an action and click SQL to see the SQL for that action.
Remember to turn it off when you are done as it will have a small performance hit.
In SQL Server you can drill down to "Performance Tools" --> SQL Server Profiler.
Using the SQL Server Profiler you can start a trace of the database your system is attached to.
By performing the action you want to watch, you will see the trace fill with queries caused by the action. You can then pause the trace and dissect each query and figure out what is going on.
You can filter the types of things you see in the trace. And by selecting a row, the query or action executed shows the details in the display at the bottom. You can then copy and paste that into a query editor of your choice and discover.

SQL Server Express 2012. Creating an audit using profiler

SQL Server 2012. Using SQL Server Profiler. How can I set the trace to only display to the results table audit type details? Such as whoever logged in, when a user makes a CRUD query, date and time etc. Just to be able to log and see who made changes in case anything happens at the database level.
Basically I do not want to include all of the stored procedures from displaying.
Thank you.
When you click on new trace in the profiler, go to Events Selection tab in the trace properties window and select whichever event you want to log.
Regards,
Sumit

SQL server profiler in the background with data saved to table

I want to run sql server profiler in the background. I know you can use SQL Trace but I want the trace info saved in a table and not in a file, and as far as I know you can only save to a file using SQL Trace.
What I am trying to do is leave sql trace running in the background and whenever an asp page generates a 500 error I send an email to the admin. Among the IIS related info in the email, I also want to include the last 50 lines from the trace. That is why I need the info in a table, so I can easily send it in the email.
You can use SQL Profiler (in 2005 / 2008) to save the results to a table by selecting the Save to table checkbox when creating the trace.
Note: Before proceeding you should read this article

What tool to capture values passed into SQL Server procedure

I have a DLL, for which I do not have the source code. It is making calls to a stored procedure in a SQL Server 2005 database. I need to know what values it is passing in as the parameters of the call.
Is there a free tool, or one that comes with SQL Server that is able to monitor and record the calls into a database?
Thanks.
You can use for this SQL Server Profiler which comes with SQL Server.
If you have an access to Microsoft SQL Server Management Studio, you find it by clicking Tools → SQL Server Profiler.
When it starts, click Connect. On Trace properties dialog, click Run. It then collects every call to the SQL Server and displays the summary at the top, and the query with its parameters at the bottom of the window.
You can also:
Pause or stop the profiler (icons in the toolbar),
Clear the current trace.
Do not forget to clear the trace before launching the action which will call the stored procedure and do not forget to pause/stop the profiling after you get the results to avoid getting too much information to analyze.
As pointed in the comments, if you are using SQL Server Express, the profiler may be missing. You may want to install a third party profiler for SQL Express instead.
Check the [Tools] menu in SQL Server Management Studio:
If you don't see this option, you most likely have SQL Server EXPRESS which does not come with Profiler.

Getting current connection properties in SQL Server

In MS SQL Server, the Database Properties dialog has the "View Connection Properties" link over on the left. Clicking that brings the "Connection Properties" dialog with properties of the current connection, such as Authentication Method, Network Protocol, Computer Name, etc...
Is there a way to get that information programmatically by running a sql query? What would that query look like?
SQL 2005 and after you interrogate sys.dm_exec_connections. To retrieve your current connection properties you'd run:
select * from sys.dm_exec_connections
where session_id = ##SPID
The field values depend on the protocol used to connect (shared memory, named pipes or tcp) but all contain information about authentication method used, protocol and client net address.
Yes you can, but it depends on which property you are after as the ones displayed in the connection properties UI come from several places.
It uses several queries (such as xp_msver and select suser_sname()) to get hold of some properties, but it also uses the xp_instance_regread stored procedure to get hold of some values from the registry of the server.
Pretty much everything that is done is management studio when interacting with the SQL engine can be done using SQL. Starting a profiler session and doing the actions in the UI will uncover what (sometimes obscure/undocumented/unsupported) SQL is being run.
From client tool perspective you could use CONNECTIONPROPERTY:
For a request that comes in to the server, this function returns information about the connection properties of the unique connection which supports that request.
SELECT ConnectionProperty('net_transport') AS [Net transport],
ConnectionProperty('protocol_type') AS [Protocol type];
DBFiddle Demo
I think the answer is 'no'.
Computer information is stored on the computer.
Connection information is most likely stored in a configuraton file or in MS SQL Server.
But have a look at the MSSQL system tables and see what properties they have.