Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 About T-Sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-03-11 : 07:22:23
sundar writes "Question : 1

If i am executing the following script but i'm getting error while runing the script

The following is the coding:
============================
Declare @SvrName as varchar(50)
Declare @Uname as varchar(50)
Declare @Result as int
SELECT @SvrName =@@servername
print @SvrName
SELECT @Uname = SYSTEM_USER
print @uname
Declare @Exec_str as varchar(200)
SET @exec_str = "master..xp_cmdshell 'osql -S " + @SvrName + " -U " + @Uname +" -P rank -d sal -i C:\ScriptRank.sql' "
EXEC @Result = @exec_str
if @Result=0
print 'success'
else
print 'failed'
I have already created the database sal. I want to attach the script scriptranl.sql in the sal database. While doing like the above code i'm getting the error following error

Could not find server 'master' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.
failed . But i have got the permission for system Administrator.In the current database.

Question 2:
Is it possible to create a database through Stored procedure?. If so how can i pass the database name as parameter"

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-11 : 08:34:30
EXEC (@exec_str)

or

SET @exec_str = 'osql -S ' + @SvrName + ' -U ' + @Uname +' -P rank -d sal -i C:\ScriptRank.sql'
EXEC master..xp_cmdshell @exec_str

(and don't use " as a string delimitter).


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -