Since SQL Server does not have a simple batch command line executor for the scripts the are auto generated from management studio, I created one.
The problem arises when delphi ado syntax and SQL Server syntax don't agree (BUT ITS THE SAME THING).
Well any how, the go I replaced with ;
Now as I declare a stored procedure alter, I hit a brick wall.
The script I'm running is :
ALTER Procedure [dbo].[procName]
as
Declare #param int
and the error i get is :
the arguments are from the wrong type,
out of range or collide with one
another.
(my free translation)
questions :
why is this happening?
what can i do to change this?
is there another udl based program that parse SQL scripts?
thanks.
edit: require login to the db with udl file.
could it be that delphi has problems with # ?
Since SQL Server does not have a
simple batch command line executer for
the scripts the are auto generated
from management studio, I created one.
Are you aware of SQLCMD ?? Seems like a command-line utility to execute SQL scripts to me... also: the SQLCMD utility has a number of additional enhancements that go beyond what the T-SQL scripts in SSMS can do.
Also check out:
SQLCMD reference
Using SQLCMD utility
Not sure about your SQL example above, but does the stored procedure actually have any parameters, or are you calling a variable inside the body #param? The usual syntax is:
ALTER Procedure [dbo].[procName]
(<#params here>)
AS
<body + variables here>
MSDN - Alter Procedure
removed the component and change the code from
ado.open;
to
ado.execute;//or something like this
solved it.
Related
I'm working to make some fact tables (taking some data from some resources, doing some transformations and putting them in a table). My main dilemma is that I can't run any SQL query other than select, update, and insertion. As soon as i try:
exec someProcedure
or a conditional statement (if #part1 ...) or even (create table ...) I take errors. Opening the task to build my SQL statements and find problems it gives errors ranging from (The Set SQL construct or statement is not supported.) to (The EXEC SQL construct or statement is not supported.).
I looked for numerous topics here on stackoverflow but none were actually addressing me problem.
Thanks,
You can see a view of what I'm facing in this picture :
I expect to run my SQL commands as usual in SSIS.
Try changing the SQL Source Type from Direct Input to Stored Procedure and just specify the stored procedure name instead of Exec stored procedure
Also make sure that you have selected the relevant TargetServerVersion from the project configuration:
How to change TargetServerVersion of my SSIS Project
Based on your comments, you are using SQL Server 2012 with Visual Studio 2010 which are not compatible.
You have to use Visual Studio 2012 or 2015+ (backward compatibility added). You can refer to the SSIS tag wiki for more info:
https://stackoverflow.com/tags/ssis/info
When trying to automate reading out constraint information using sp_helpconstraint I got the bright idea of pulling out the source code of the built-in SP directly and run it myself (since it returns multiple result sets so those can't be stored in a temp table). So I ran exec sp_helptext 'sp_helpconstraint' (on SQL Azure) to generate the source code, and copied it into a new query window.
However, when I run the SP (on SQL Azure), I get lot's of error messages -- for example, that object syscomments doesn't exist even though I am using the exact same source that runs perfectly when calling sp_helpconstraint directly. Just to make sure it wasn't an anomaly with the procedure or a mistake in my copy/paste execution, I tested the exact same procedure on SQL Server 2008, and if I directly copy the SP source into a new query window, it runs perfectly (obviously after removing the return statements and manually setting the input parameters).
What gives?? Do built-in SP's run in a special context where more commands are available than normal on SQL Azure version? Is sp_helptext not returning the actual source that is being run on SQL Azure?
If you want me to try anything out, give a suggestion and I can try it on our SQL Azure Development instance. Thanks!
Like the title says, in oracle you can issue the following command in SQL*Plus:
SQL> select something from anothertable; #sql
SQL> #{/home/me/somescript.sql}; #load sql from file and execute it
SQL> do something else in script; #other sql
Without having to file->open the sql script to load it to the UI.
Is there an equivalent in SQL Server Query Manager? I've stumbled upon many situation where i could have used it but i couldn't be able to find a way to accomplish it.
You're not really comparing like for like Tools here.
The equivalent tool to SQL*Plus in SQL Server is the SQLCMD Utility.
In particular you will be interested in the -i switch as this allows you to provide a .sql file as input.
Edit:
In response to your comment, you could look to use the system stored procedure xp_cmdshell to launch a prompt form within a T-SQL batch that allows you to use SQLCMD. Not the most elegant solution in my opinion but it should work.
If using latter versions of SQL Server (2005 & 2008), see if the :r command in SQLCMD works for you:
:r <filename>
Parses additional Transact-SQL statements and sqlcmd commands from the file specified by <filename> into the statement cache.
If the file contains Transact-SQL statements that arenot followed by GO, you must enter GO on the line that follows :r.
From sqlcmd Utility
Use isql utility http://msdn.microsoft.com/en-us/library/aa214007(SQL.80).aspx
issql ... -iinputfile
There is also SQLS*Plus tool that you can use to execute scripts within a script
I'd like to write a stored procedure in SQL 2005 to script all my database objects to a file. The only problem is...I have no idea how to do it. Can anyone help?
Thanks!
you can try something like this,
First of all creating a new store procedure in your SQL server, like this.
CREATE PROCEDURE ListObjectsToFile
AS
BEGIN
select * from sysobjects;
END
GO
And then call it from the Command Line, indicating your complete connection string and the path/name of the output file
C:\>sqlcmd -S
yourServer\yourSQLServerInstance -U yourUser -P yourUserPassword -q
ListObjectsToFile -o C:\list.txt
Hope that helps,
Santi! :)
I know your question says that you want a Stored Procedure to do the job done, but if you want an other solutions, I would be using SMO in VB.NET. When accessing database objects with the .NET objects, they all got a "Script()" function which returns the SQL to use to recreate the object. A table for instance.
Hope this might help
Try DBSourceTools. (http://dbsourcetools.codeplex.com)
Its open source, and specifically designed to script an entire database
- tables, views, procs and data to disk, and then re-create that database through a deployment target.
I want to call a sproc on server B from server A in TSQL without linking the servers. Is it possible to use something like a connection string to execute this sproc? The return will be a single nvarchar value.
Regards.
To avoid "linked servers", you'd normally use OPENDATASOURCE
After comment:
EXEC OPENDATASOURCE('SQLNCLI', 'Data Source=London\Payroll;Integrated Security=SSPI').remoteDB.remoteSchema.remoteProc #param1, #param2,...
Simple 4 part naming convention. The whole OPENDATASOURCE simply replaces the linked server name...
Note: you may have issues with "adhoc access"
i know of no way of doing it without ...
creating an extended stored proc to do it for you
perhaps using xp_cmdshell to use isql to execute your stored proc .. however, getting the result might be tricky (perhaps write the result to a table on your current server in the same sql file that isql is reading)
-don