PDA

View Full Version : Error - deleting a Record


dips255
05-05-2009, 08:42 AM
I get the following error when i use rs.delete

Microsoft SQL Native Client error '80004005'

Could not find server 'NS3' 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.

Any help

Spudhead
05-05-2009, 02:27 PM
Without seeing what code you're trying to execute, we're pretty much blind I'm afraid.

dips255
05-06-2009, 07:12 AM
The code is as follows

set rsDel = Server.CreateObject("Adodb.Recordset")
rsDel.open "select img_path from admin_images where img_id='"&img_id&"'",con,1,3
if not rsDel.eof then
set fsd = server.CreateObject ("scripting.FileSystemObject")
ImageName = replace(trim(rsDel("Img_path")),prefix,"")
ImagePath = server.MapPath("../upimages/" &ImageName)
if fsd.FileExists(ImagePath) = true then
fsd.DeleteFile(ImagePath)
end if
set fsd=nothing
rsDel.delete 'Error occurs here
end if
Call CloseRec(rsDel)

Old Pedant
05-06-2009, 09:10 PM
Ummm...it seems really unlikely that the error you reported derives from that code.

Possible, but unlikely.

Can you please check the LINE NUMBER that the error is coming from and indicate to us which line in your code it is??

OH! WAIT! I just realized: Is your variable con a *string*??? That is, a connection string as opposed to a connection *object*???

If so, can you show us the contents of the string?

If you don't know the answer, add a line of debug to find out:

...
set rsDel = Server.CreateObject("Adodb.Recordset")

' add the following two lines temporarily for debugging:
Response.Write "con is type " & TypeName(con) & "<p>"
Response.Write "value of con is " & con & "<HR>" & vbNewLine

rsDel.open "select img_path from admin_images where img_id='"&img_id&"'",con,1,3
if not rsDel.eof then
...

dips255
05-07-2009, 08:26 AM
i checked it
con is connection object

Old Pedant
05-07-2009, 09:09 PM
Then again, it seems unlikely that the error is from the code you showed.

It would be much more like to arise when the connection is opened.

Can you add some more debug code (that is, Response.Write's) to pin down the actual point of error?

No, wait... I keep second guessing myself.

Hypothetical:

Suppose that in this query
select img_path from admin_images where img_id=xxx
the table admin_images is actually supposed to be in a linked-to server.

That is, that particular table is supposed to be located on server "NS3".

Then I guess the error message might indeed be:
Could not find server 'NS3' in sys.servers. ...

Now, possibly the reason that admin_images is unavailable is because the *permissions* to that linked "NS3" server havent been granted to the IUSR_xxx account and/or whatever account the connection "con" was opened with??

What happens if you use a SQL Server tools (e.g., MMS or QA) to make that same query? Is it allowed??? If so, then I'd have to assume that indeed it's a permissions problem. Your personal account has the needed permissions but not whatever account is being used by the "con" connection object.

Just grasping at straws here, really. Can you show the connection string used to open the "con" object??? Obscure any username or password, of course.

dips255
05-08-2009, 08:48 AM
Thanks for your replies

My problem got resolved

This error was because the server was renamed after SQL Server was installed on it.

I got the solution here
http://msdn.microsoft.com/en-us/library/ms143799.aspx

Old Pedant
05-08-2009, 10:13 PM
Huh...so really strange that the error occurred on the recordset open instead of on the open of the connection.

Oh, well...glad it's fixed.