Cor Ligthert [MVP]
7/2/2008 5:00:00 PM
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" <Reg@discussions.microsoft.com> schreef in bericht
news:8F59CFB0-5588-4660-839E-CFAE724F264E@microsoft.com...
> 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[MVP]" wrote:
>
>> 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" <Reg@discussions.microsoft.com> schreef in bericht
>> news:A3EEDE4B-3556-45BB-B5B0-F11FBC08A982@microsoft.com...
>> >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'
>>