Error when trying to create new SQL Server login via ado.Net

H

holysmokes99

I get an error when I try to execute the following code using ADO.Net
in VB.Net:

conn.open
sqlString="CREATE LOGIN test WITH PASSWORD = '1qaz2wsx'"
command=new SqlCommand(sqlString)
command.connection = conn
command.ExecuteNonQuery()

The error occurs when executing the ExecuteNonQuery line and is:

"Line1: Incorrect syntax near 'LOGIN' "

The database connection is connected to the master database of SQL 2005
Express using the sa account. This line executes just fine in Sql
Server Studio Manger when connected as sa. Am I not allowed to create
database logins via ado.net?!?! I need to for my application.

Thx,
Marcus
 
M

MSMVP KenLin for VB.NET

Dear Holysmokes99,

Suppose it should work, the syntax and codes are all correct.
Would you show us the Connection string?


--
Hope this help and welcome to reply the testing result.

Regards
Ken Lin, Kam Hung
Founder and VP of Hong Kong .NET User Group(http://HKNetUG.com)
MCP, MCP+I, MCDST, MCSA, MCSE(NT4 & win2k),
MCSE+I, MCDBA(SQL7 & SQL2K), MCSD(VB6 & .NET), MCAD(.NET)
Microsoft Community Star(Hong Kong & Taiwan)
Microsoft Most Valuable Professional(.NET since 2003)
MCT2004 & 2005
 
H

holysmokes99

Hi, KenLin

The connection string is "server=marcus; Initial Catalog=master;
uid=sa;password=whatever!". I am able to connect fine to the database
using this ADO.Net connection as I have just prior to the CREATE LOGIN
command executed several other standard queries on the server.

Cheers,
Marcus
 
M

Marcus

Oh, Jeesh, My bad!!! I was connecting to an
instance of SQL Server 2000, and not SQL Express. I have both on my
machine
and forgot to reference it as "Marcus\SQLEXPRESS", instead using
"Marcus" only. CREATE LOGIN is new for SQL Server 2005 and thus I got a

syntax error when connecting to SQL 2000. Sorry about that!

Marcus
 

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