create sql server login (TSQL) ?

S

Sagaert Johan

Hi
How can i create an sql server login (sql 2005 express) ?
I have my TSQL code ready but how can i run it from c#?

How can i execute TSQL code from Csharp, or are there better ways using some
of the
Microsoft.SqlServer.Management classes to manage server logins?



Johan
 
A

Alberto Poblacion

Sagaert Johan said:
How can i create an sql server login (sql 2005 express) ?
I have my TSQL code ready but how can i run it from c#?

How can i execute TSQL code from Csharp, or are there better ways using
some of the
Microsoft.SqlServer.Management classes to manage server logins?

You can execute your TSQL code from C# in the same way as any DML
statement, using the ExecuteNonQuery method of a SqlCommand:

using System.Data.SqlClient;
....
string sql = "CREATE LOGIN test WITH PASSWORD='test'";
SqlCommand cmd = new SqlCommand(sql, myConnection);
cmd.ExecuteNonQuery();
 

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