Running SQL script in SqlCmd with SQL Server Express

1.8k views Asked by At

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?

1

There are 1 answers

4
Solomon Rutzky On BEST ANSWER

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.