1

I have developed a C# application connecting to a SQL Server database. I now wish to test the application on the client PC, and so I scripted the database and now wish to deploy it on the client PC.

The client PC is running SQL Server Express, however SQL Server Management Studio is not installed and so I thought I would use SqlCmd to execute the script on the local server of the PC. Note: when I installed SQL Server Express I set the instance name to MSSQLSERVER.

enter image description here

The problem I'm having is with the command I'm typing :

-S SomePCName\MSSQLSERVER -i C:\CreateDBSql.sql

When I run the command, I get the following message:

enter image description here

What am I doing wrong?

4
  • 2
    Did you specify the database name in your script? else -d <databasename> Commented Jun 21, 2015 at 8:53
  • The script should create a new database. So there is no need to specify the database name. Commented Jun 21, 2015 at 15:14
  • What is the full command line that you are running? Why did you specify an instance name? The default instance name for SQL Server Express is SQLExpress, but is MSSQLServer for the other editions. Also, what do you mean "nothing happens"? How long did you wait? There is a connection timeout and command timeout, so it won't sit there forever. Commented Jun 21, 2015 at 15:56
  • I just updated OP. Hope it helps. Commented Jun 22, 2015 at 7:48

1 Answer 1

3

The problem mainly appears to be that you are not running SQLCMD correctly. Command-line parameters (or "flags" or "switches") need to be entered on the, well, command line ;-). Try the following (note the use of (local)):

SQLCMD -S (local)\MSSQLSERVER -i C:\CreateDBSql.sql

UPDATE:
It seems that since MSSQLSERVER is the default "default instance" name, it is reserved and cannot be used in a connection string explicitly. In this case you can try the following:

SQLCMD -S (local) -i C:\CreateDBSql.sql

If that doesn't work, then it might be best to reinstall SQL Server Express while using a different instance name: either the preferred default instance name for SQL Server Express (i.e. SQLExpress) or something that is neither SQLExpress nor MSSQLSERVER.

Sign up to request clarification or add additional context in comments.

4 Comments

Will this work for express? I heard once that express uses (local) with some additional text? Thank you!
@MarnusSteyn Try it and you will see ;-). Yes, it does work and I tried it myself. You are getting confused with the related product: SQL Server Express LocalDB, which uses (localdb)\InstanceName. (local) is the preferred syntax for referring to the local machine for non-LocalDB instances.
Tried it, and updated the OP. At least I'm one step forward from where i was. I am getting a response now from the server, but it is complaining.
@MarnusSteyn I added an UPDATE: section to my answer with more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.