Viewing ExecuteQuery String

J

jim_adams

Given a technique similar to the following, instead of actually
executing the Stored Procedure, I need the resulting SQL command string
written to a file and then manually executed in Query Analyzer.

Dim objSqlConn As New SqlClient.SqlConnection
Dim objSqlDA As New SqlClient.SqlDataAdapter
Dim objSqlCmd As New SqlClient.SqlCommand
objSqlConn = New SqlConnection(strSqlConn)
With objSqlCmd
objSqlConn.Open()
.CommandTimeout = CommandTimeout
.CommandType = CommandType.StoredProcedure
'Add some SPROC parameters
.Parameters.Add(DbParameter)
.CommandText = Command
.Connection = objSqlConn
End With
objSqlDA.SelectCommand = objSqlCmd
if blnWriteToScriptFile then
'How to do this????????
else
objSqlDA.Fill(objDS)
end if

Any ideas are greatly appreciated?

Thanks,

Jim
 
W

William \(Bill\) Vaughn

The final product generated by ADO.NET is not exposed as a public property
unless you enable Trace. What you can do is use the Profiler to see what's
generated and sent to the server.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
J

jim_adams

Hi Bill,

Thanks for the suggestion.

The problem is that to generate the Trace, the SQL statements have to
be run. Certain times, especially when dealing with shared SQL
clusters, a DBA needs to manually review and run scripts via Query
Analyzer. Having a binary app do this without DBA review is against
policy. So in this case, instead of running the SPROCS, my app needs
to produce a work file.

Thanks again for your help.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top