Link to home
Start Free TrialLog in
Avatar of mstumpo
mstumpoFlag for United States of America

asked on

Error running an SQL express backup script

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)
ASKER CERTIFIED SOLUTION
Avatar of dba2dba
dba2dba

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mstumpo

ASKER

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.
Avatar of mstumpo

ASKER

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