Cannot find server when run stored procedure - sql-server

I have a database backup from a client. This database has a SP that I am trying to execute. I am getting the following message:
Msg 7202, Level 11, State 2, Procedure SP_NAME, Line 24
[Batch Start Line 2]
Could not find server 'InstanceName' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
I also looked into inside of the SP and see that it references tables that are not in the DB I am running the stored prog from, they are in another DB. Somehow the stored prog runs fine on the client side. The client says they do not use any linked server. Any idea what my error message actual means?
Thanks

Related

Trying to EXEC a stored procedure on another server

I created a stored procedure in a database called DBA_Test. I went to another server and tried to execute this stored procedure using
EXEC *LinkedServerName*.DBA_Test.dbo.spLoad_Clients_Monthly_Filings
When I try to execute the query, I get the following error:
Server 'LinkedServerName' is not configured for RPC.
When the line is in the query window of SSMS, the DBA_Test is underlined in red and hovering over it shows a message:
Could not locate entry in sysdatabases for database 'DBA_Test'. No entry found with that name. Make sure that the name is entered correctly.
I have everything spelled correctly and the stored procedure is listed in the database as seen here:
I tried executing the stored procedure on the same server, but from another database, and it ran fine. Every other server I switched to gave the red line error saying that the database could not be found in sysdatabases. I have all the linked servers working correctly.
When you create linked server you need to set RPC (and maybe RPC out):
Regarding your second question, sometimes SSMS doesn't correctly parse linked server objects

Error while execute db to server

Have tried for hours to execute my db to my server, but keeps getting the same error.
What I did first what on my local dbd i did go to tasks -> generate scripts where I under scripts options chose schema and data. After the script was generated, I logged in to my hosts server, where i dragged the database in to my SQL Server Management Studio. Then I removed all the following text:
Gist with text
and replaced the USE [aspnet-Billigcsgosalgssite-20170731103725] with
USE sql6003.smarterasp.net
After that I did the execute, and got the following error code:
Msg 911, Level 16, State 1, Line 1
Database 'sql6003' does not exist. Make sure that the name is entered correctly.
Msg 102, Level 15, State 1, Line 223
Incorrect syntax near '.'.
I really don't know what to do anymore, and would be happy for some help!
I think first you need to create database on your local machine
create database sql6003
After this run the script that you have taken from different server

sp_reset_connection error in SQL Azure Linked Server RPC

I have a problem calling a remote Stored Procedure (RPC) on my SQL Azure, passing through a Linked Server (build on a Sql Server 2008 R2 instance: 10.50.2550.0 - x64 - Enterprise Edition).
This issue is not difficult to reproduce, and it's not really related with "calling" the Stored Procedure, but with its internal execution (I think)...
Take a look to my simple code:
CREATE PROCEDURE [dbo].[myStoredProcedure]
#AccountId INT = NULL
AS
BEGIN
DELETE FROM [dbo].[myTable];
INSERT INTO [dbo].[myTable] (Col1, Col2)
SELECT DISTINCT
Value1
, Value2
FROM [dbo].[myTableSource];
END
GO
GRANT EXECUTE ON [dbo].[myStoredProcedure] TO [myDbRole]
GO
When I launch this through my Linked Server, using this code (on a connection from my local instance, where the Linked Server has been created)...
EXEC('[AZURE_LINKEDSERVER].[myDatabase].[dbo].[myStoredProcedure] #AccountId = NULL')
...I get this error (that seems a warning!):
Message 2812, level 16, state 62, row 1
Could not find stored procedure 'sp_reset_connection'.
And obviously I checked everywhere and I'm not calling that Stored Procedure...that I think it's internally used by Sql Server.
I also tried this code, same result:
EXEC sp_sqlexec '[AZURE_LINKEDSERVER].[myDatabase].[dbo].[myStoredProcedure] NULL'
The Linked Server has "remote RPC enabled" (rpc and rpc out options are both set to True) and works great with other Stored Procedure and every other OPENQUERY code I used until now: also permissions work fine.
The strange thing is that the first part of the SP is correctly executed (I see query result count in the Messages window of SSMS), but the second is not called at all.
Can you please tell what's the SP sp_reset_connection is related to?
Do you know a workaround to call my SP without errors?
I tried everything...
SQL Azure in use has version 11.0.9231
sp_reset_connection is not an actual stored procedure it is a flag in the TDS stream that says "Reset the connection" so you can use connection pooling. It should exist on all SQL Servers implicitly but cannot be called by your code.
what type of linked server have you setup? follow this to create a linked server to azure:
http://blogs.msdn.com/b/sqlcat/archive/2011/03/08/linked-servers-to-sql-azure.aspx

Cross-server SQL query to read from one table (shared) and write to another (local)

I've been having a very difficult time trying to read a table on one server and writing to another existing table on my hard drive (local... created using SQL Server Express).
Here's my code:
insert into [DPS-ABC1DE2\SQLEXPRESS].my_LOCAL_DATABASE.dbo.SHIPMENTS
select
CUST_NUMBER,
SHIPMENT_ID,
SHIP_DATE,
MODE_CODE,
MILES,
WEIGHT,
AMOUNT_PAID
from SHARED_DATABASE.dbo.SHIPMENTS
where datepart(year,SHIP_DATE)= 2012 and datepart(month,SHIP_DATE) = 1
I get the following error message when I run this:
Msg 7202, Level 11, State 2, Line 7
Could not find server 'DPS-ABC1DE2\SQLEXPRESS' in sys.servers. Verify that the correct
server name was specified. If necessary, execute the stored procedure
sp_addlinkedserver to add the server to sys.servers.
So I've tried using
EXEC sp_addlinkedserver [DPS-ABC1DE2\SQLEXPRESS]
but I get this error:
"Msg 15247, Level 16, State 1, Procedure sp_MSaddserver_internal, Line 29
User does not have permission to perform this action."
I'm a rookie SQL programmer, so I've had to research this extensively but with no success. Any help would be appreciated!
sp_addlinkedserver execute permissions default to members of the sysadmin and setupadmin fixed server roles. Check out this link on how to sort it out on sql server 2005.
Once you get rid of that issue you could use the following to link and login to the other server.
--add the linked server and then login
EXEC sp_addlinkedserver 'DPS-ABC1DE2\SQLEXPRESS',N'SQL Server';
EXEC sp_addlinkedsrvlogin #rmtsrvname='DPS-ABC1DE2\SQLEXPRESS',
#useself='false',
#rmtuser='login_username',
#rmtpassword='login_password'
--do your job here
Insert into [DPS-ABC1DE2\SQLEXPRESS].my_LOCAL_DATABASE.dbo.SHIPMENTS
Select...
--drop the linked server login and then drop the server
EXEC sp_droplinkedsrvlogin 'DPS-ABC1DE2\SQLEXPRESS', NULL
EXEC sp_dropserver 'DPS-ABC1DE2\SQLEXPRESS', NULL;
Hope this helps...

SQL Server 2000 xp_cmdshell

Using SQL Server 2000 I am trying to use this command in Query Analyzer
xp_cmdshell 'del c:\delete-me-file.txt'
and I'm getting this error:
Server: Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'xp_cmdshell'.
Basically I want to delete this file from the system... what command do I need to run to do this?
You need to be in the context of the master database or prefix the extended stored procedure with the db name.
EXEC master..xp_cmdshell 'del c:\delete-me-file.txt'
If this command succeeds it would indicate that the SQL Server service account probably has too many permissions however.

Resources