Solved

Error running an SQL express backup script

Posted on 2010-11-18
3
321 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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now