SQL server profiler in the background with data saved to table - sql

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

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

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.

Who is accesing my sql table?

I took over someones job and need to find out from where certain tables are being read. Is there a way to do that? The more information I could get about the caller the better.
I am using MS SQL Server 2000.
If you want to see the full detail of all queries that are being run against the server, including the hostname and username of the client calling it, you'll want to run a trace.
You can use the SQL Profiler tool to run a short trace, but I prefer to run a "server-side" trace to a file, which I can examine later.
See the SQLServerPedia article here: http://sqlserverpedia.com/wiki/The_Server-side_Trace:_What,_Why,_and_How
You might also run a network sniffer process to watch the raw connections.
You could add a trigger to the table you want to be audited and insert relevant data into an audit table from there.
E.g. http://www.devx.com/dbzone/Article/7939/1954
If you can get on the server while your table is being accessed, look into the undocumented stored procedure sp_who2.

Logging ODBC, SQL Server

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.