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!
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
I have a server called ERP-SERVER, and a server called SQLDEV-SERVER.
They both have a blob instance, but we never copy over the complete blob to the SQLDEV-SERVER as that would be too much data.
So when trying to access a file on our test server, it should first check if that file exists on the SQLDEV-SERVER, and if not check if the file exists on the ERP-SERVER. This is where it goes wrong. This piece of code (SQL) used to work but somewhere along the way it broke. I have narrowed it down to the inter database query just returning completely different results.
so for instance i run this query on the ERP-SERVER instance in SQL management studio:
SELECT count(*)
FROM [erp-server].[Extranet_Blob].[dbo].[FileStorBlob]
this returns 223221 results.
When i run the same query on the SQLDEV-SERVER instance in SQL management studio, it returns 313 results.
It points to the same server and same database, yet a completely different count, which is why it is also not returning the files from the live environment when it is not found on the dev environment.
Any pointers as to where this problem could be situated?
Look very carefully at your linked server definition. When you are running the query on SQLDEV-SERVER it is using the linked server definition of that name rather than necessarily the ERP_Server. Is it possible that someone has fiddled with the definition?
While comparing Database instance to a Database project in VS2010 using SSDT, it shows a difference in one of the Stored Procedures. The Store Procedure DDL script is exactly the same but when I expanded the Properties folder under the Store Procedure it show a difference in the DefaultExpressionScript.
The source SP shows this in the DefaultExpresionScript:
DefaultExpressionScript = at
While the destination SP has this:
DefaultExpressionScript = -1
I don't see where I can change this there is no such object called DefaultExpressionScript in my database project. where should I fix this?
This bug is still present in VS 2015 Update 3 with SSDT 14.0.61021.0. However, just scripting the stored procedure with ALTER ... in SSMS and running that query (which shouldn't change anything) fixed it for me. The schema comparison didn't show differences anymore afterwards.
The DefaultExpressionScript is the default value of one of the stored procedure's parameters. I suggest using Script As to get the TSQL definition of the stored procedure from the database and verifying that the stored procedure default values match what's in your database project.
Also, note that there have been a large number of bug fixes to schema comparison that aren't available in VS2010. Have you considered installing the latest version of Visual Studio 2015 Express with SSDT?
I finally found a workaround. You simply script the affected SP(s) for Modify and run the Alter statement, without changing anything. It corrects the values.
I am a new database intern working with a access front end and SQL server backend database. The database was custom made for the company. One of my assignments is to take scripts and apply them to make four new tables. I am aware that I need to make a new query for each new table but I don't know if I should make the query in SQL server management studio or the frontend access program. I have tried copying and pasting the given scripts into a new query in access but I get an error message "invalid SQL statement expected 'DELETE', 'INSERT'...". I decided to try to break done the program a little bit and tested the first line
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =OBJECT_ID(N'[dbo] .[FK_tblInstrumentInterfaceLog_tlkpInstrument]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblInstrumentInterfaceLog]'))
but the same error message keeps popping up. I even tried just SELECT * FROM sys.foreign_keys, and I got the error message "could not find file...". I am very much a beginner and any guidance would be appreciated.Basically am I supposed to be applying these scripts the server SQL database or on the front end access program?
Are you using a pass-through query? i.e. not just a select query. Access needs to know where to send the query and since you are using TSQL not Access SQL this needs to be executed on the server.
Normally when you query a linked table the information of how to get the data (the connection string) is tied to the table. But for this kind of query you'll probably need to tell Access explicitly. Unless you are using an ADP/ADE, then the connection info travels with the program not the table.
As a general rule, you use SQL management studio (SSMS) to create and run those scripts. So the general accepted approach here is such scripts will not be placed in the front end. As noted such scripts if for some reason must be placed in the front end, then you have to create them as pass-though, but EVEN in this case you want to use the SSMS to create such quires.
So the answer here is you create the new scripts and make table queries in the back end, or in this case using the SQL server management studio.
The syntax checking, query editor etc. in recent versions of SSMS now has auto-complete etc. and you can test/write/update those scripts in SQL server. Once you have such a query or even several of them, then the resulting “several” statements can be pasted into a front end query that been created as pass-though. If you do not use a pass-though query, then you are creating and using and assuming client side SQL (JET (now called ACE)).
The client side has it own version of SQL syntax, and it is NOT 100% compatible with the SERVER SIDE. If you writing SQL in the client that is NOT pass though, then you using a linked table to SQL server. These linked tables thus will use local (JET/ACE) based SQL queries. The ODBC driver thus translates this SQL into server side compatible syntax. However the JET/ACE sql syntax is very limited when compared to SQL server and no server side commands exist in this SQL syntax for the client data engine (JET/ACE)
So for many quires, you will and can simply build such queries using the Access query builder.
However for SQL that needs to run 100% server side then such quires has to be setup as pass-though and are in most cased built + tested using SSMS.
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.