Showing posts with label sqlexpress. Show all posts
Showing posts with label sqlexpress. Show all posts

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.

login to database failed...

Hi,

I am using VS2003 with SQLExpress on my local machine. I am trying to configure an app to connect to a loca sql express database. The following is
the connection string that I am using and the error message that I am receiving.

Any ideas what the problem is?

<add key="connectionString" value="Server=IKITSCH\SQLEXPRESS;database=Test1;trusted_connection=true" />


Cannot open database "Test1" requested by the login. The login failed. Login failed for user 'IKITSCH\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "Test1" requested by the login. The login failed. Login failed for user 'IKITSCH\ASPNET'.

Source Error:


Line 1600: {
Line 1601: SqlConnection conSql = new SqlConnection(ConnectionString);
Line 1602: conSql.Open();
Line 1603: return conSql;
Line 1604: }

Source File: c:\inetpub\wwwroot\testsite\classes\config.cs Line: 1602

Stack Trace:


[SqlException: Cannot open database "Test1" requested by the login. The login failed.
Login failed for user 'IKITSCH\ASPNET'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +472
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
eStreamBG.Dating.Classes.DB.Open() in c:\inetpub\wwwroot\testsite\classes\config.cs:1602
eStreamBG.Dating.Classes.DBSettings.Get(String Key) in c:\inetpub\wwwroot\TestSite\Classes\DBSettings.cs:125
eStreamBG.Dating.Classes.DBSettings.Get(String Key, String Default) in c:\inetpub\wwwroot\TestSite\Classes\DBSettings.cs:75
eStreamBG.Dating.Classes.Misc.get_SiteEmail() in c:\inetpub\wwwroot\testsite\classes\config.cs:1719
eStreamBG.Dating.Classes.EmailQueueItem.Create(String to, String subject, String body) in c:\inetpub\wwwroot\TestSite\Classes\Email.cs:224
eStreamBG.Dating.Classes.ExceptionLogger.Log(String source, Exception ex) in c:\inetpub\wwwroot\TestSite\Classes\Exceptions.cs:122

Many Thanks!


------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Hi

You are using integrated security for authentication to the SQL Server database.

ASP.Net runs with the identity of the ASPNET user account by default and this user account has limited rights.

Try to avoid integrated security and specify the user name and password for the SQL Connection String instead.

And make sure you DB name isTest1 not test1Smile

|||That means the login account used to open the connection does not have access to the requested database Test1. Since the connection use Trust_connection and Impersonate is not enabled, IIS?use?its?account?machinename\ASPNET?to?connect?to?database?then?causes?the?failure.?To?solve?this,?open?Management?Studio->connect?to?SQLExpress->navigate?to?Security->Logins->check Properties of IKITSCH\ASPNET->switch?to?User?Mapping?tab->add?mapping?to?the?Test1?database?and?give?sufficient?permissions?to?the?mapped?database?user?for?future?operations?on?Test1?database.?

You can download Management Studio Express from here:

http://msdn.microsoft.com/vstudio/express/sql/download/|||

Hi,

Many Thanks!

|||

Hello,

I am also experiencing the same problem as 'chemystery', and I too have used integrated security in my connection string for authentication to the SQL Server.

I have contacted the DB and server administrators to find out if they can give me the username and password so that I can include it in my connectionstring but they have refused as they say it breaches their security protocols.

Is there another way around this that will allow integrated security and allow access to the DB?

Thanks in advance!


|||Then you have 2 options:
Walkthrough: Encrypting Configuration Information Using Protected Configuration

Or?ask the database host to add your Windows account?to?SQL?logins?and?give?it?proper?permissions,?so?that?you?can?the?same?Windows?Identity?when?opening?connection?with?Integrated?Security.?To?ensure?to?use?your?account?to?open?conneciton?for?each?web request,?you?can?use?impersonation?with?credentital, please refer to: identity Element