Stored Procedure stopped working - sql

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.

Related

Looking for sys.sp_add_ct_history

Context:
I'm investigating a claim that the stored procedure sys.sp_add_ct_history is running and causing some slowness on a particular database after updating to SQL Server 2016 SP3. The only mention from Microsoft documentation just says:
SQL Server 2016 SP3 ...introduced a new table, dbo.MSchange_tracking_history, and a new stored procedure, sys.sp_add_ct_history, to record the history of change tracking cleanup.
This database is indeed using SQL Server Change Tracking on a number of tables, and dbo.MSchange_tracking_history has records. So far, so good.
The issue:
I cannot find sys.sp_add_ct_history anywhere.
EXEC sys.sp_add_ct_history gives a "Could not find stored procedure" error.
I've also tried querying all_objects:
SELECT name FROM sys.all_objects
...and I return various sys stored procedures, but not that one.
Anybody up to speed on this stored procedure? Anything weird about it? Is it extra hidden somehow? Are there permissions I should check for? This doesn't add up and I'm not sure what I'm missing.

SQL Server 2012 XP_DELETE_FILE is Missing

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 ...

SQL Server 2005 How to ignore errors during Create Procedure

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.

Running synchronous commands to between two sql servers

I'm running a stored procedure on server1 from my application. The stored procedure does a bunch of stuff and populate a table on server2 with the result from the procedure.
I'm using linked server to accomplish this.
When the stored procedure is done running the application continues and tries to do some manipulation of the result from the stored procedure.
My problem is that the results from the stored procedure has not been completely inserted into the tables yet, so the manipulation of the tables fails.
So my question is. Is it possible to ensure the insert into on the linked server is done synchronous? I would like to have the stored procedure not return until the tables on the linked server actually is done.
You can use an output parameter of the first procedure. When the table is create on the second server the output parameter value will be return to your application and indicates the operation is ready.
If the things are difficult then this you can try setting a different isolation level of your store procedure:
http://msdn.microsoft.com/en-us/library/ms173763.aspx
I found the reason for this strange behavior. There was a line of code in my stored procedure added during debug that did a select on a temporary mem table before the data in the same table was written to the linked server.
When the select statement was run, the control was given back to my application and at the same time the stored procedure continued running. I guess the stored procedure was running synchronously from the start.

How do I publish an alteration to a replicated stored procedure (SQL 2000)?

We have several stored procedures marked as articles for replication in our SQL2000 database. If we update any of them via ALTER PROCEDURE, the changes are applied to the master, but never published to subscribers. Am I missing a setting, or does SQL require a complete reinitialization/snapshot to move the changes out?
Here are two ways to update the stored procedure on master and subscribers
Drop the replication article on the stored procedure, and recreate it
Use the sp_addscriptexec stored procedure to replicate then execute a script containing the alter procedure command on the master and all subscribers
Source: http://www.replicationanswers.com/General.asp