Scripts failing without error

R

Reg

I have some simple scripts to create databases and add users/roles. The
scripts run just fine in Management Studio. When I run them programmitcally
they execute without any errors, however nothing happens; neither the users
nor the databases are created.

Here's an example for adding a user and setting role to sysadmin:

-- Get Major Version of Sql Server
-- 8 = Sql Server 2000
-- 9 = Sql Server 2005
DECLARE @version nvarchar(128)
select @version = LEFT(CONVERT(nvarchar(128),
SERVERPROPERTY('productversion')), 1)

-- Store traffic user and password
DECLARE @cmduser varchar(128)
DECLARE @cmdpass varchar(128)

select @cmduser = 'myuser'
select @cmdpass = 'mypassword'

DECLARE @userid int

-- Create user if doesn't exist
if @version = '9'
begin
--if not exists (select * from [master].[sys].[syslogins] where name =
@cmduser)
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = @cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

if @version = '8'
begin
-- Is there a proper way to do this in SQL Server 2000?
if not exists (select * from [master].[dbo].[sysxlogins] where name =
@cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

-- Give user system admin privileges
--EXEC master..sp_addsrvrolemember @cmduser, 'sysadmin'
EXEC master..sp_addsrvrolemember @loginame = @cmduser, @rolename = 'sysadmin'
 
C

Cor Ligthert[MVP]

Reg,

Did you see the word dotnet in this newsgroup name, while this is even a
special adonet newsgroup.

There was nowhere written SQL server newsgroup, that are complete other
ones.

Cor
 
R

Reg

Yes I saw dotnet. I have a c# program that runs the included script, doesn't
report any errors, but nothing happens on the database. My problem is with
ado.net. When I run the script in the management studio it works just fine
and the users or databases actually get created.

Cor did you even read my question? Or do you just feel the need to police
the forums without actually offering any help?

Cor Ligthert said:
Reg,

Did you see the word dotnet in this newsgroup name, while this is even a
special adonet newsgroup.

There was nowhere written SQL server newsgroup, that are complete other
ones.

Cor

Reg said:
I have some simple scripts to create databases and add users/roles. The
scripts run just fine in Management Studio. When I run them
programmitcally
they execute without any errors, however nothing happens; neither the
users
nor the databases are created.

Here's an example for adding a user and setting role to sysadmin:

-- Get Major Version of Sql Server
-- 8 = Sql Server 2000
-- 9 = Sql Server 2005
DECLARE @version nvarchar(128)
select @version = LEFT(CONVERT(nvarchar(128),
SERVERPROPERTY('productversion')), 1)

-- Store traffic user and password
DECLARE @cmduser varchar(128)
DECLARE @cmdpass varchar(128)

select @cmduser = 'myuser'
select @cmdpass = 'mypassword'

DECLARE @userid int

-- Create user if doesn't exist
if @version = '9'
begin
--if not exists (select * from [master].[sys].[syslogins] where name =
@cmduser)
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = @cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

if @version = '8'
begin
-- Is there a proper way to do this in SQL Server 2000?
if not exists (select * from [master].[dbo].[sysxlogins] where name =
@cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

-- Give user system admin privileges
--EXEC master..sp_addsrvrolemember @cmduser, 'sysadmin'
EXEC master..sp_addsrvrolemember @loginame = @cmduser, @rolename =
'sysadmin'
 
C

Cor Ligthert[MVP]

Reg,

As you show your dotNet code, then it is fine, but there was not one word C#
in it, all was pure SQL script.

Did you know that these newsgroups are searched by others for there ADONET
problems.
So people have to go now trough your message thinking there is something
about C# with failing scripts.
But there is not anything there.

However you are not the only one who does not care about others, but luckily
those are rare.

Cor

Reg said:
Yes I saw dotnet. I have a c# program that runs the included script,
doesn't
report any errors, but nothing happens on the database. My problem is with
ado.net. When I run the script in the management studio it works just fine
and the users or databases actually get created.

Cor did you even read my question? Or do you just feel the need to police
the forums without actually offering any help?

Cor Ligthert said:
Reg,

Did you see the word dotnet in this newsgroup name, while this is even a
special adonet newsgroup.

There was nowhere written SQL server newsgroup, that are complete other
ones.

Cor

Reg said:
I have some simple scripts to create databases and add users/roles. The
scripts run just fine in Management Studio. When I run them
programmitcally
they execute without any errors, however nothing happens; neither the
users
nor the databases are created.

Here's an example for adding a user and setting role to sysadmin:

-- Get Major Version of Sql Server
-- 8 = Sql Server 2000
-- 9 = Sql Server 2005
DECLARE @version nvarchar(128)
select @version = LEFT(CONVERT(nvarchar(128),
SERVERPROPERTY('productversion')), 1)

-- Store traffic user and password
DECLARE @cmduser varchar(128)
DECLARE @cmdpass varchar(128)

select @cmduser = 'myuser'
select @cmdpass = 'mypassword'

DECLARE @userid int

-- Create user if doesn't exist
if @version = '9'
begin
--if not exists (select * from [master].[sys].[syslogins] where name =
@cmduser)
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name =
@cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

if @version = '8'
begin
-- Is there a proper way to do this in SQL Server 2000?
if not exists (select * from [master].[dbo].[sysxlogins] where name =
@cmduser)
begin
EXEC sp_addlogin @cmduser,@cmdpass
end
end

-- Give user system admin privileges
--EXEC master..sp_addsrvrolemember @cmduser, 'sysadmin'
EXEC master..sp_addsrvrolemember @loginame = @cmduser, @rolename =
'sysadmin'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top