Wednesday, March 7, 2012

Login to SQL Server Express using Command Prompt

How can I login to SQL Server Express instance(localhost\SqlExpress) using command prompt so that I can query database. Is there any alternative GUI tool for SQL Server Express Manager? (I think Microsoft has discontinued SQL Server Express Manager). I prefer using Command Prompt. I am using WindowsXP Professional.Have you looked for an osql.exe? I'd personaly look in the installation directory of the sql express and look at all the .exe files and see what's there.|||

oSQL is supported, but SQLCmd is the 2005 equivalent that is recommended. Simply open a command prompt and open the connection to your server as in:

SQLCmd -S .\sqlexpress -E

This will take you to a prompt where you can start typing commands. More information about SQLCmd is available in Books Online.

Regards,

Mike Wachal
SQL Express team

-
Mark the best posts as Answers!

|||

I don't have SQL Server Express Manager. I want to enable ASPNET account in SQL Server Express so that my ASP.NET application can access databases created in SQL Server Express.

How can I accomplish above task using Command Promt. If anyone recommend any GUI tools other than Express Manager it may be even better.

Thanks a lot for your support.

|||

You can download Management Studio Express from http://msdn.microsoft.com/vstudio/express/sql/download/. If you want to use the command line, use SQLCmd as I suggested above.

Once you've connected using SQLCmd, you will need to write T-SQL statements to create Logins and Users for the ASPNET user. You should be able to find information about creating Logins and Users in the Books Online at http://msdn2.microsoft.com

Regards,

Mike Wachal
SQL Express team

-
Mark the best posts as Answers!

|||

Now I can connect to SQL Server Express using Command Prompt but I get some error messages when I use T-SQL commands.Following are the commands I used.

D:\Documents and Settings\Sankar>sqlcmd -S .\sqlexpress
1> use BookShop
2> SELECT Name FROM Department
3> GO

I receive following error message when I type above SELECT statement .

Msg 911, Level 16, State 1, Server JAMESGAT-5BB8A7\SQLEXPRESS, Line 1
Could not locate entry in sysdatabases for database 'BookShop'. No entry found
with that name. Make sure that the name is entered correctly.
1>

|||

Oops, I forgot to specify the path. The command should be typed as below.

sqlcmd -S .\sqlexpress -d D:\Inetpub\wwwroot\BookShop\App_Data\BookShop.mdf

We can perform T-SQL queries after connecting to the database as described above.

No comments:

Post a Comment