SQL Server Profiler does not show data in SQL statement - sql-server

I am using the SQL Server Profiler to trace the SQL generated from nHibernate in a Windows SmartClient appplication.
The trace of the SQL statement does not show actual data, but rather, looks like this:
exec sp_executesql N'SELECT attachment0_.RecordKey as RecordKey1_, attachment0_.Id as Id1_, attachment0_.Id as Id87_0_, attachment0_.RecordType as RecordType87_0_, attachment0_.RecordKey as RecordKey87_0_, attachment0_.FileName as FileName87_0_, attachment0_.OriginalFileName as Original6_87_0_, attachment0_.DateTimeAttached as DateTime7_87_0_ FROM MyDatabase.dbo.tblAttachment attachment0_ WHERE attachment0_.RecordKey=#p0',N'#p0 int',#p0=262
Is there a way to see the the actual data in the SQL command?

It's just showing the parameterized sql. If you want to log or to show non-parameterized sql I came up with a solution to this here:
Execute NHibernate-generated prepared statements in SQL Server Management Studio
The item of note is the log4net appender that basically translates this in the accepted answer.

Related

VB.net parameterized query uses sp_executesql but loses UTF8 characters

I have an odd scenario that I'm looking for some clarification on.
I currently have an VB.net application that is sending the parameterized query below to an SQL Server 2019 database using ADO.net. To make the database support UTF8, we are using one of the new _UTF8 collations. For this test, we are using a database configured to use Latin1_General_100_CI_AI_SC_UTF8.
Query:
exec sp_executesql
N'UPDATE Roles SET Name = #pName WHERE Role_ID = 6',
N'#pName varchar(1000)',
#pName='æææDeveloper'
Now, I know that when I run the query above in MSSQL Management Studio, I don't lose my 'æ' characters but if I run this through code, my characters are replaced by '?'. My question is why would I lose them through code via ADO.net and not through MSSQL Management Studio.
I also know that sp_executesql does not support varchar as parameters which was the main problem and we were able to solve but again. Why would it work in MSSQL but not in ADO.net?

Oracle dbms_xplan.Display() equivalent to SQL Server 2017

I am converting some sql from Oracle to SQL Server 2017.
One of SQL code is having dbms_xplan.Display() inside the script.
I want to know what is the equivalent of dbms_xplan.Display() in SQL Server 2017.
You could use
SHOWPLAN_TEXT:
Causes Microsoft SQL Server not to execute Transact-SQL statements. Instead, SQL Server returns detailed information about how the statements are executed.
SET SHOWPLAN_TEXT ON;
GO
-- your query
GO
SET SHOWPLAN_TEXT OFF;
GO
or if you want to execute query:
STATISTICS PROFILE
Displays the profile information for a statement. STATISTICS PROFILE works for ad hoc queries, views, and stored procedures.
When STATISTICS PROFILE is ON, each executed query returns its regular result set, followed by an additional result set that shows a profile of the query execution.
Last option is to use SHOWPLAN_XML to get nice graphical overview in SSMS.

How do I print query inside a prepared statement for SQL Server?

I had been working with a MySQL database and a JDBC connection. In that case I could easily print a prepared statement using System.out.println(ps);.
But for a SQL Server database it just prints 'SQLServerPreparedStatement' instead of the actual query that will be sent to the server after the parameters have been substituted into the SQL command. How can I accomplish that with SQL Server JDBC?I do not want to achieve that by manual coding like passing all parameters to a function and then bulding the query inside.I want to print it as soon as the query gets executed with effective parameters
You can't. From https://learn.microsoft.com/en-us/sql/connect/jdbc/reference/sqlserverpreparedstatement-class :
"SQLServerPreparedStatement prepares a statement by using the SQL Server sp_prepare stored procedure"
Therefore the final SQL isn't actually held by the JDBC driver.

Timeout for long-running queries with RODBC & MS SQL Server

I have to run an SQL query that iterates cursor over a larger table (MS SQL Server 2014). It would be rather difficult not to use a cursor for this particular purpose.
The cursor-related code is kept in a stored procedure. R only evaluated EXEC dbo.do_something. EXEC dbo.do_something works as expected when running the code from MS SQL Management Studio. When I run it via RODBC, the query aborts without error message after 30 secs. I guess this is the value of "Connection Timeout".
What options do I have to make the query work with R?
It seems the answer to my particular problem is rather simple: Add SET NOCOUNT ON to the proc definition.

Executing SQL Server stored procedure in sql squirrel

i'm in ubuntu 9.04 and using sql squirrel as my sql client. i connect to a remote SQL Server. There are some stored procedures in the db. I don't know how to execute them. No explicit gui. Earlier i was in windows and i could use management studio. I can right click on stored procedures and give Execute. You guys have any idea? Let me know. It will be helpful for me. :)
Typically, if you want to execute a SQL Server stored procedure, you'd write:
EXEC Your-stored-proc-name-here #param1 = value1, #param2 = value2
and then execute that command. Typically, you should also use the dbo.StoredProcName notation to avoid any confusion / problems.
EXEC <STOREDPROCNAME> <PARAMLIST>
EXEC dbo.GetCandy 'Red',62
Then hit execute or the equivalent in your editor.
I had to tweak it slightly for a Microsoft SQL Server database (jsqlconnect driver). This worked for me:
execute <sproc_name> <args>

Resources