[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error running an SQL express backup script

Posted on 2010-11-18
3
Medium Priority
?
342 Views
Last Modified: 2012-05-10
Running SQL express we need to run an automatic backup. I created the script, but get this error when we run it.
Script
SET J=%date:~-10,2%  
SET A=%date:~-4%  
SET M=%date:~-7,2%  
SET H=%time:~0,2%  
SET MN=%time:~3,2%  
SET S=%time:~-5,2%  


IF "%time:~0,1%"==" " SET H=0%HOURS:~1,1%  

SET DIRECTORY="D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\backup"

set FILE=%DIRECTORY%\sqlbackup_%J%_%M%_%A%_A_%H%_%MN%_%S%.bak

cd d:\Program Files\Microsoft SQL Server\90\Tools\Binn  

sqlcmd -S Server_name\SQLEXPRESS -E -Q "BACKUP DATABASE [JA2010] TO  DISK = N'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\JA2010.bak' WITH NOFORMAT, INIT,  NAME = N'JA2010-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10"

Error:
System.Data.DataException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at SQLScheduler.Data.DataWorker.OpenConnection()
   at SQLScheduler.Data.DataWorker.RunSQL(String p_strSQL, Int32 commandTimeout, DataSet& dataResults)
   --- End of inner exception stack trace ---

Server stack trace:
   at SQLScheduler.Data.DataWorker.RunSQL(String p_strSQL, Int32 commandTimeout, DataSet& dataResults)
   at SQLScheduler.Data.DataWorker.RunSQL(String p_strSQL)
   at SQLScheduler.Data.DataWorker.CheckSQL(String script)
   at SQLScheduler.Services.JobService.CheckSQLSyntax(String serverName, String jobName, String script)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at SQLScheduler.Services.JobService.CheckSQLSyntax(String serverName, String jobName, String script)
   at SQLScheduler.Client.JobForm._btnCheckSyntax_Click(Object sender, EventArgs e)
0
Comment
Question by:mstumpo
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
dba2dba earned 2000 total points
ID: 34167529
The error message indicates that the sqlcmd was not able to connect to the Server name Server_name\SQLEXPRESS.

Please double check if the server name is correct, if remote connections and protocols are enabled.

Thanks,

0
 

Author Comment

by:mstumpo
ID: 34175836
Server name is correct. 2003exchange is the name. Remote connections are allowed and both TCP and Named Pipes are enabled. I changed the timeout and that did not help.
0
 

Author Comment

by:mstumpo
ID: 34175854
ok so i am a moron, the server name was not changed to 2003exchange. My bad please close this question, thanks for pointing me in the right direction
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Integration Management Part 2
Screencast - Getting to Know the Pipeline

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question