Search code examples
sql-serverdatabase-connectionsqlcmd

Why I cant connect to instance of sqlserver?


I have 3 instance of sql server:

MSSQLSERVER
SQLEXPRESS
SQLEXPRESS2008R2

I want to connect to SQLEXPRESS2008R2 by this command:

sqlcmd -s .\SQLEXPRESS2008R2 -e

and than run this command:

use Dbs_TickSoft
go

but show me this error:

Database 'Dbs_TickSoft' does not exist...

If my database is connected:

enter image description here


Solution

  • Looking at the sqlcmd doc, there is a difference between the -s (lower case) and -S (upper case) arguments. The former specifies the column-separator character, while the latter specifies the SQL instance instance of to connect to. So changing your command to

    sqlcmd -S .\SQLEXPRESS2008R2 -e
    

    with the upper case "S" should work.