Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:27:00+00:00 2026-06-13T22:27:00+00:00

Scenario : I am creating a admin tool in C# which will restore a

  • 0

Scenario :
I am creating a admin tool in C# which will restore a full sql server backup in a server and apply the transaction logs. After db come up. I have run a few scripts shown below.

use master
EXEC sp_addlogin '<destsid>', '<sidadmpass>','<dbname>'
use <dbname>
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
EXEC sp_change_users_login 'Update_One','<destsid>','<destsid>'
use master
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use msdb
EXEC sp_grantdbaccess '<destsid>'
EXEC     sp_addrolemember 'db_owner', '<destsid>'
use model
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use tempdb
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use master
grant all on xp_cmdshell to <destsid>
EXEC sp_addsrvrolemember '<destsid>', 'serveradmin'
EXEC sp_addsrvrolemember '<destsid>', 'dbcreator'
EXEC sp_addsrvrolemember '<destsid>', 'bulkadmin'
use <dbname>
if object_id('sp_change_sapuser') is not null
    drop procedure sp_change_sapuser 
create procedure sp_change_sapuser @oldid sysname, @newid sysname
as begin
declare @oldid_uid  smallint
declare @newid_uid  smallint    
declare @object     sysname
declare @object_full    nvarchar(999)
set @oldid_uid = user_id(@oldid)
set @newid_uid = user_id(@newid)
if @oldid_uid is not null and @newid_uid is not null
begin
declare object_cursor cursor local for 
select name from sysobjects where((xtype='U' and name <> 'dtproperties') or (xtype='V' and name not in ('syssegments','sysconstraints')) or (xtype='P' and name not like 'dt_%') or (xtype='D' and name not like 'DF__dtpropert%') or (xtype in ('FN','TF','IF'))) and @oldid_uid = uid
open object_cursor
fetch next from object_cursor into @object
while @@fetch_status=0
begin
set @object_full = user_name(@oldid_uid) + '.' + @object
exec sp_changeobjectowner @object_full, @newid
fetch next from object_cursor into @object
end
end
else
if @oldid_uid is null
begin
print '*** old database user does not exist ***'
end
if @newid_uid is null
begin
print '*** new database user does not exist ***'
end
end
exec sp_change_sapuser '<sourcesid>', '<destsid>'
use master
EXEC sp_grantlogin   'AMR\<destsid>adm'
EXEC sp_grantlogin   'AMR\SAPService<dbname>'
EXEC sp_defaultdb    'AMR\<destsid>adm','<dbname>'
EXEC sp_defaultdb    'AMR\SAPService<dbname>','<dbname>'
EXEC sp_addsrvrolemember 'AMR\<destsid>adm',     'sysadmin'
EXEC sp_addsrvrolemember 'AMR\SAPService<dbname>', 'sysadmin'
EXEC xp_sqlagent_proxy_account 'SET', '<servername>', 'SAPMssXPUser',N'<sidadmpass>'
use master
EXEC sp_addlogin '<destsid>', '<sidadmpass>', <dbname>
use <dbname>
EXEC sp_change_users_login 'Update_One','<destsid>','<destsid>'
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use master
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use msdb
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use model
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use tempdb
EXEC sp_grantdbaccess '<destsid>'
EXEC sp_addrolemember 'db_owner', '<destsid>'
use master
grant all on xp_cmdshell to <destsid>
EXEC sp_addsrvrolemember '<destsid>', 'serveradmin'
EXEC sp_addsrvrolemember '<destsid>', 'dbcreator'
EXEC sp_addsrvrolemember '<destsid>', 'bulkadmin'
--EXEC xp_sqlagent_proxy_account 'SET', '<servername>', 'SAPMssXPUser', N'<sidadmpass>'
EXEC sp_grantlogin   '<destsid>adm'
EXEC sp_grantlogin   'SAPService<dbname>'
EXEC sp_defaultdb    '<destsid>adm','<dbname>'
EXEC sp_defaultdb    'SAPService<dbname>','<dbname>'
EXEC sp_addsrvrolemember '<destsid>adm',     'sysadmin'
EXEC sp_addsrvrolemember 'SAPService<dbname>', 'sysadmin'

Note : values given will be replaced with actual values.

While running these scripts few may throw exceptions. But i want to continue even though some scripts throws error. And also i have removed GO(batch terminator) because i cannot add separate dll into server. Please suggest some idea to get this problem solved.

Details :
Programming lang : C#
Db – Sql Server 2005,08

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:27:01+00:00Added an answer on June 13, 2026 at 10:27 pm

    You can’t just miss out the GOs. For some statements (e.g. CREATE PROCEDURE), it is important that they exist in their own separate batch.

    GO is an instruction to client tools (e.g. SSMS) that it should send the preceding text (back to the previous GO or the start of the script, whichever is later) to the server as a batch. So if you’re sending SQL to the server through code, you ought to do the same thing – or have each batch stored as separate pieces of text so you don’t have to worry about parsing the text (think about multi-line string literals that may contain the word GO).

    For each batch (originally delimited by GOs in your original script), you need to send that as a separate batch to the server by calling ExecuteNonQuery or similar – then create a new SqlCommand object (or replace the text of the existing one) with the next batch to be executed.

    You might then decide to deal with any errors the come from the SQL execution in your C# code, and just move to setting up the next batch and executing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im creating an IPad Application which will have an SQL Server backend. My question
Scenario : Creating a server which has Room objects which contain User objects. I
we are creating a WinForms .NET4 app with MS SQL Server and we are
I have the following scenario: I have a ShoutCast-ish server which serves out radio
here's my first! quick rundown: SCENARIO i'm creating an app in which you can
here's the scenario: I'm creating a page in the wordpress admin. I created a
I have a confusing scenario regarding transaction rollbacks with Spring. I am successfully creating
Detailed scenario is like this : I am creating 10 buttons using a loop
I have a scenario that, I am creating dynamic html content and I need
I'm running into the classic scenario where, when creating Word COM objects in .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.