By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Mar 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"holysmokes99" <ho**********@hotmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
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

Mar 29 '06 #2

P: n/a
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

Mar 29 '06 #3

P: n/a
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

Mar 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.