Exception thrown after restoring the database using Smo.

Posts   
 
    
Animal
User
Posts: 11
Joined: 20-Nov-2008
# Posted on: 20-Nov-2008 06:21:20   

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(List1 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.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-Nov-2008 10:42:18   

This is the link you mentioned: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4388

That's because the connection pool should be flushed too.

Please check this thread: https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3376091&SiteID=1

Animal
User
Posts: 11
Joined: 20-Nov-2008
# Posted on: 20-Nov-2008 11:31:22   

Thanks for the quick response. I followed the link and got rid of the exception, thank you. simple_smile

(removed the other 3 redundant copies of this post sunglasses -- Otis)

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-Nov-2008 11:45:25   

Waw, 4 replies to thank me simple_smile I like to think of it as it was intended wink

You're welcome.

Animal
User
Posts: 11
Joined: 20-Nov-2008
# Posted on: 21-Nov-2008 02:43:38   

Thanks for the quick response. I followed the link and got rid of the exception, thank you. simple_smile

Animal
User
Posts: 11
Joined: 20-Nov-2008
# Posted on: 21-Nov-2008 02:46:36   

I am really sorry, on click of 'Post' I am getting an exception page, so I tried it many times without knowing that it is already posted smile . How can I delete the unintended ones? wink

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Nov-2008 05:16:22   

Hehe smile , you can't I think. Don't worry. If I delete your unintended post, I have to delete your last one, and the Walaa's post. Cheers.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 21-Nov-2008 09:47:34   

Removed the redundant posts simple_smile

Frans Bouma | Lead developer LLBLGen Pro