I have inherited an SQL Server 2012 database that has a stored procedure which references a master database stored procedure called XP_DELETE_FILE. The stored procedure is failing because the XP_DELETE_FILE is not present in the master database. It seems to be an undocumented procedure and I don't know where I can source it. Any suggestions on a how to resolve this issue?
Thanks,
F.
You are attempting to access the system extended procedure using the dbo schema. This was changed some time ago to use the sys schema.
Change this:
EXEC master.dbo.xp_delete_file ...
To this:
EXEC master.sys.xp_delete_file ...
Related
This seems like it would be trivial, but I have not been able to come up with a solution to this small problem.
I am attempting to create a stored procedure in my application's database. This stored procedure just executes a job that has been set up in the SSMS on the same server (seemed to be the only way to programmatically execute these jobs).
The simple code is shown below:
USE ApplicationsDatabase
GO
CREATE PROCEDURE [dbo].[procedure]
AS
BEGIN
EXEC dbo.sp_start_job N'Nightly Download'
END
When ran as is, the procedure technically gets created but cannot be executed due to it not being able to find the 'sp_start_job' since it is using the ApplicationsDatabase. If I try to create the procedure again (after deleting previously created) but updating the USE to MSDB, it tries to add it to that system database for which I do not have permissions to do. Finally, I attempted to keep the original create statement but added the USE MSDB within the procedure (just to use the 'sp_start_job' procedure), but it would error saying USE statements cannot be placed within procedures.
After pondering on the issue for a little (I'm obviously no SQL database expert), I could not come up with a solution and decided to solicit the advice of my peers. Any help would be greatly appreciated, thanks!
You will have to fully qualify the path to the procedure. Of course, you can only execute this is the application has permissions.
Try this:
USE ApplicationsDatabase
GO
CREATE PROCEDURE [dbo].[procedure]
AS
BEGIN
EXEC msdb.dbo.sp_start_job N'Nightly Download'
END
I need to create a Stored Procedure in SQL Server 2005. Somewhere in the procedure, I have to join to a table which does not exist in the test environment but in the live environment (in a database in a linked server). I will not run the procedure in the test environment, but I need it to exist in order to create the ORM code in the application.
Naturally, SQL Server raises the error "Could not find server 'xxx' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedur sp_addlinkedserver to add the server to sys.servers.". However, I know that I can't add this server to the test environment, as it is not accessible from outside.
So, my question is, how can I create my stored procedure by ignoring the errors? Is there a way for it?
This is an old thread, but if other people are having the same problem, here's another solution:
You can have your server via text and the procedure will pass.
create proc test
as
declare #myserver varchar(50) = '[myserver\myinst]'
exec('select * from '+#myserver+'.dbo.table')
This way, the proc will compile on any environment, but will only run successfully on production
If you are certain that everything is correct and the procedure will work fine in live environment then create a fake linked server using sp_addlinkedserver.
What I mean is, if procedure body contains a linked server named test_linked and if it's not found then it will throw error.
Use sp_addlinkedserver and create a fake linked server named test_linked pointing to your test environment or even live environment. that will solve the issue cause it will try to check whether a linked server named test_linked does exist in sys.servers or not but unless you are running the procedure the actual linked server will not be accessed (AFAIK).
As Aaron Bertrand have mentioned in comment, Going by synonym would be a much cleaner approach though.
I am presently updating a procedure with multiple EXEC lines such as:
EXEC databasename.tablename.pr_sys_drop_Object 'zt_Staging_of_class'
yet nowhere have I found the definition of EXEC in this context.
If it's a full three part name where the middle part is not the name of a table but of a schema a kind of SQL namespace. So in that context pr_sys_drop_Object is a stored procedure in a separate schema.
If you look in the named database, in the named schema you'll probably find a stored procedure called pr_sys_drop_Object.
Execute is a sql server keyword see the docs here for more details. It is used to execute stored procedures or raw sql.
In your case it seems to be executing the procedure databasename.tablename.pr_sys_drop_Object and passing in 'zt_Staging_of_class' as a parameter to that procedure.
Does dynamic SQL work in phpMyAdmin?
I tried the most basic examples from http://www.youtube.com/watch?v=MiAwOoelu9k
For instance, each of these throws an error (tried separately):
EXEC ('SELECT data FROM table')
EXEC sp_executesql N'SELECT data FROM table'
I found the answer in multiple Stackoverflow streams (listed below). It depends on the version of phpMyAdmin, which needs to be v3.5.2.2 or higher. This is because Dyanamic SQL is part of a STORED PROCEDURE. Older versions of phpMyAdmin allow you to CREATE a STORED PROCEDURE, but the ability to CALL a STORED PROCEDURE within phpMyAdmin requires version 3.5.2.2 or higher. (Source: is it possible to run a stored procedure from within phpmyadmin 3.4.10.1?)
For those using an older version of phpMyAdmin who need to use Dynamic SQL, an alternative is Workbench (http://www.mysql.com/products/workbench/)
For those using phpMyAdmin version 3.5.2.2 or higher, to CREATE and CALL a STORED PROCEDURE, here are posts of other users:
How to write a stored procedure using phpmyadmin and how to use it through php? How to write a stored procedure using phpmyadmin and how to use it through php?
MySQL procedure not getting created/working using phpmyadmin mysql procedure not getting created/working using phpmyadmin
How do I view my stored procedures in phpMyAdmin? How do I view my stored procedures in phpMyAdmin?
I created several stored procedures in phpmyadmin, how to call them using an sql query? I created several stored procedures in phpmyadmin, how to call them using an sql query?
I have a stored procedure that I'm positive of has no errors but I recently deleted the table it references but imported a backup with the same name exactly and same column settings (including identity) that the previous one had but now it doesn't work.
Is there any reason that having deleted the table but importing a new would break the stored procedure?
BTW: Running Microsoft SQL Server Express Edition w/ IIS.
you can try to recompile the stored procedure with:
exec sp_recompile YourProblemTableNameHere
this will recompile all procedures that use the YourProblemTableNameHere table. But that is just a guess based on the very limited info given.