Hi,
I am using 2.6 final version of LLBLGen Pro with Adapter template group.
Runtime library version is v2.0.50727 and the database is SQL server 2005 and .Net version is 2.0.
I am getting an exception while executing any query after I do a database restore using Smo [Microsoft.SqlServer.Management.Smo namespace]
I think there is a similar thread already in this forum, but that link is not working [throwing some exception - link is llblgen.com/TinyForum/GotoMessage.aspx?MessageID=24065&ThreadID=4388].
Below is the sequence of actions I perform:
1) Restoring the database using the code given below:
string databaseName = ConfigurationManager.AppSettings["CatalogNameToUse"];
// Create a new connection to the selected server name
srvConn = new ServerConnection(serverName);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Give the login username
srvConn.Login = userName;
// Give the login password
srvConn.Password = password;
// Create a new SQL Server object using the connection we created
Server srvSql = new Server(srvConn);
// Loop through the databases list
// Create a new database restore operation
Restore rstDatabase = new Restore();
// Set the restore type to a database restore
rstDatabase.Action = RestoreActionType.Database;
// Set the database that we want to perform the restore on
rstDatabase.Database = databaseName;
// Set the backup device from which we want to restore, to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem(filePath, DeviceType.File);
// Add the backup device to the restore type
rstDatabase.Devices.Add(bkpDevice);
// If the database already exists, replace it
rstDatabase.ReplaceDatabase = true;
// Kill all connections
srvSql.KillAllProcesses(databaseName);
rstDatabase.Wait();
// Perform the restore
rstDatabase.SqlRestore(srvSql);
2) Trying to execute a simple query and it throws the exception given below:
An exception was caught during the execution of a retrieval query: A transport-level error has
occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No
process is on the other end of the pipe.). Check InnerException, QueryExecuted and Parameters of this
exception to examine the cause of this exception.
Details: at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchDataReader(IRetrievalQuery
queryToExecute, CommandBehavior readerBehavior)
at CST.BusinessEntities.DataAccess.DataAccessAdapter.FetchDataReader(IRetrievalQuery queryToExecute,
CommandBehavior readerBehavior) in C:\CST\CST.DataAccess\DataAccessAdapter.cs:line 292
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors,
IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary2 typeConvertersToRun)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List
1 valueProjectors,
IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32
maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean
allowDuplicates, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors,
IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32
maxNumberOfItemsToReturn, Boolean allowDuplicates)
at CST.DataFacade.DataAccessFacade.FetchProjection(List`1 valueProjectors, IGeneralDataProjector
projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn,
Boolean allowDuplicates) in C:\CST\CST.DataFacade\DataAccessFacade.cs:line 1077
System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to
the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean
breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.WriteSni()
at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode)
at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean
inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior
runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior
runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior
runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
When I execute the same query again, it works fine. I know that it is the 'KillAllProcesses' causing the problem. But I need it to get exclusive access to restore the database.
Do I need to add anything in the LLBLGen related code or it needs to be done in the SQL restore code?
Thanks for any help.
Ani.