Home All Groups Group Topic Archive Search About

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

Author
28 Mar 2006 11:26 PM
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

Author
29 Mar 2006 1:33 AM
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

Show quote
"holysmokes99" <holysmoke***@hotmail.com> wrote in message
news:1143588372.890003.112870@z34g2000cwc.googlegroups.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
>
Author
29 Mar 2006 6:20 PM
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
Author
29 Mar 2006 7:09 PM
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

AddThis Social Bookmark Button