S
Steven
Hi
I am running a C# application on a machine connected to a NT network.
The application creates SQL scripts and executes them.
I am using SQLConnection and SQLCommand objects.
The concept is to take a text file, and for each username in the text
file, create a database, and give that person's NT account access to
that new database only.
The first script, which is a 'CREATE DATABASE' script works fine..
databse is created exactly as specified. This is done with a command
object, and EXECUTENONQUERY()
Second step is to grant the NT user access to the machine. I create a
string that is my script, and at runtime it looks something like this:
EXEC sp_grantlogin 'DOMAIN\Username'
I have also tried:
EXEC sp_grantlogin [DOMAIN\Username]
In both cases, the system throws exception at that point:
An unhandled exception of type 'System.Data.SqlClient.SqlException'
occurred in system.data.dll
Additional information: System error.
This occurs on the EXECUTENONQUERY call (surprise surprise).
Here is some of the code (oh by the way, connection string points to
the Master table, not sure what else I should have pointed at for a
server level function?)
string script_userCreate = "EXEC sp_grantlogin [" + AccountName +
"]";
sqlC = new System.Data.SqlClient.SqlCommand(script_userCreate, dbc);
dbc.Open();
sqlC.ExecuteNonQuery();
dbc.Close();
I am now thinking work around with SQLDMO, would this be a worthwhile
approach instead? (Is Interop.SQLDMO.dll redistributable?)
Appreciate any help...
Cheers,
Steven Nagy
(Brisbane, Australia : yes aussies can program too)
([email protected])
I am running a C# application on a machine connected to a NT network.
The application creates SQL scripts and executes them.
I am using SQLConnection and SQLCommand objects.
The concept is to take a text file, and for each username in the text
file, create a database, and give that person's NT account access to
that new database only.
The first script, which is a 'CREATE DATABASE' script works fine..
databse is created exactly as specified. This is done with a command
object, and EXECUTENONQUERY()
Second step is to grant the NT user access to the machine. I create a
string that is my script, and at runtime it looks something like this:
EXEC sp_grantlogin 'DOMAIN\Username'
I have also tried:
EXEC sp_grantlogin [DOMAIN\Username]
In both cases, the system throws exception at that point:
An unhandled exception of type 'System.Data.SqlClient.SqlException'
occurred in system.data.dll
Additional information: System error.
This occurs on the EXECUTENONQUERY call (surprise surprise).
Here is some of the code (oh by the way, connection string points to
the Master table, not sure what else I should have pointed at for a
server level function?)
string script_userCreate = "EXEC sp_grantlogin [" + AccountName +
"]";
sqlC = new System.Data.SqlClient.SqlCommand(script_userCreate, dbc);
dbc.Open();
sqlC.ExecuteNonQuery();
dbc.Close();
I am now thinking work around with SQLDMO, would this be a worthwhile
approach instead? (Is Interop.SQLDMO.dll redistributable?)
Appreciate any help...
Cheers,
Steven Nagy
(Brisbane, Australia : yes aussies can program too)
([email protected])