?
Solved

Error running an SQL express backup script

Posted on 2010-11-18
3
Medium Priority
?
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 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