Executing SQL Server stored procedure in sql squirrel - sql-server

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>

Related

Error when using parameters with SSIS in Visual Studio

I have a simple query (included below). It's used inside a loop with two parameters. It works as a charm on one server, but when I use it with another server, it fails with "Parameters cannot be extracted from the SQL command".
DECLARE #Tagnavn As varchar(250)
DECLARE #HentEnergiNiveauEfter As datetime2(7)
set #Tagnavn = ?
set #HentEnergiNiveauEfter = ?
EXEC [FDTV_PUMP_AVERAGE_CONSUMPTION_FROM_DATE] #Tagnavn ,#HentEnergiNiveauEfter
I've seen the workaround with putting the query in a variable, but this doesn't work for me. And I really don't understand why the above works on one server but not another :-)
The working set-up consists of:
-Microsoft SQL Server Data Tools for Visual Studio 2017, v15.3.3
-the stored procedure is on an SQL Server v11
The non-working set-up consists of:
-Visual Studio Community 2017 - Tools for Applications 2017, v15.7.3
-the stored procedure is on an SQL Server v10
Thanks!
Palle
Problem solved. Permission problems with the server holding the stored procedure. Thanks for your input. And #Larnu: now it works without the temp. variables :-)
Thanks again,
Palle

SQL Server Profiler does not show data in SQL statement

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.

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.

Is there a way to check if SQL SP is running or completed?

I use Misrosoft SQL Server Management Studio to work with databases. I manually started SP execution on PC One. Is there any way to check if SP is still running or not from a different PC?
The system stored procedure sp_who might be of use: http://technet.microsoft.com/en-us/library/ms174313.aspx
If you know the SPID then you can use
EXEC sp_who <spid>;
Alternatively you can use the login name of the login that executed the command
EXEC sp_who 'george\gvee';
If the cmd column states AWAITING COMMAND then this indicates that that session is not performing a query or other action i.e. it is idle
You can use SQL Server Profiler
http://msdn.microsoft.com/en-us/library/ms187929(v=sql.90).aspx
Use a free tool like Idera SQL Check. Shows graphically a lot of statatiscs about the SQL Server current state.

Execute an Oracle stored procedure from a SQL Server stored procedure

I have a SQL Server stored proc that needs to send information to an Oracle stored proc.
How do I set this up? Should it be a linked server? And how do I write the code to pass and execute the stored proc?
You could also use:
DECLARE #outputParameter int
EXEC ('BEGIN <procedureName>(?,?); END;', #inputParameter , #outputParameter OUTPUT) at <linkedServerName>
This allows capturing output parameters
a procedure "TestingProcedure" in Oracle server.
a linked Server "LinkedServer" in SQL Server.
call TestingProcedure in SQL server example:
EXECUTE ('begin TestingProcedure; end;') AT LinkedServer;
This is the syntax that I would probably try from the start:
SELECT * FROM OPENQUERY(<linked server name>, '{CALL <oracle sp>}')
What I've seen (I have not tried this myself) is that you can also use OPENQUERY to call an Oracle function which can then call the stored procedure, or you can turn the stored procedure into a function. Your connection from SQL Server would then look something like this:
SELECT * FROM OPENQUERY(<linked server name>, 'SELECT <oracle function> FROM dual')
Turns out I ended up having to use Microsofts CLR and write my own little C# application in order to handle the variables being pushed between the servers. Here's what I did:
C# Application starts on a scheduled task in windows
Application executes the SQL Server stored procedure and gets the return values
Application then executes the Oracle stored procedure with appropriate values

Resources