Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use a simple batch script to backup a local instance of SQL Express 2012, as follows:

@echo off
SET SERVER=.\\sqlexpress
set dom=%date:~0,2%
set month=%date:~3,2%
set year=%date:~6,4%
set file=%year%-%month%-%dom%
sqlcmd -S %SERVER% -d master -Q "exec sp_msforeachdb 'BACKUP DATABASE [?] TO DISK=''%BACKUP_DIR%\?.Full.%file%.bak'''

The script is failing to run with the following error:

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Client unable to establish connection due to prelogin failure.

This is on Server 2008 R2, my SQL database (on localhost) instance is named SQLEXPRESS. There is an instance of SQL Express 2008 on the system (hence client 10.0).

The database is configured to use a trusted connection, and the .net desktop software deployed on our network PCs is able to access the database without any problem.

Am I missing something obvious here, I've done a fair amount of searching for this error message, and haven't found anything that has been particularly useful so far.

share|improve this question
Databases are not configured to use trusted connections, applications are configured to connect to databases with trusted connections. – Justin Dearing Mar 21 '12 at 19:08
up vote 1 down vote accepted

Change remove one of the slashes in SET SERVER=.\\sqlexpress. It should be SET SERVER=.\sqlexpress

share|improve this answer
Thanks, that and the closing double quotes around the query were missing. – Bryan Mar 22 '12 at 8:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.