Sql Azure - Frequent timeout error - azure

I am using azure sql with many quartz windows service which runs every 2 mins. I sometimes get following error
Message:An error occurred while executing the command definition. See the inner
exception for details.|System.Data.SqlClient.SqlException (0x80131904): A
transport-level error has occurred when receiving results from the server.
(provider: Session Provider, error: 19 - Physical connection is not usable) at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean
breakConnection, Action`1 wrapCloseInAction) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,
Boolean breakConnection, Action`1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject
stateObj, UInt32 error) at
System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at
System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at
System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at
System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value) at
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,
TdsParserStateObject stateObj, Boolean& dataReady) at
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at
System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior
runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,
RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&
task, Boolean asyncWrite, SqlDataReader ds) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,
RunBehavior runBehavior, Boolean returnStream, String method,
TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
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.ExecuteReader(CommandBehavior behavior)
at
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c__DisplayClass
b.b__8() at
System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterc
eptionContext,TResult](Func`1 operation, TInterceptionContext interceptionContext,
Action`1 executing, Action`1 executed) at
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand
command, DbCommandInterceptionContext interceptionContext) at
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavi
or behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior
behavior) at
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCo
mmands(EntityCommand entityCommand, CommandBehavior behavior)
ClientConnectionId:9a85a9a9-69aa-4a68-8e05-e54adf5ac318
Any Idea how to resolve this? We are using EF 6.1 and open context in "using" block.

Found the answer here. While working with Azure SQL we should have logic to retry the database operation. EF 6.0 gives it out of the box

Related

System.Data.SqlClient.SqlException: Hint 'noexpand' on object 'View_CMS_Tree_Joined' is invalid

I upgraded Kentico from version 8.2 to 9.0. Now getting the following error.
Hint 'noexpand' on object 'View_CMS_Tree_Joined' is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Hint 'noexpand' on object 'View_CMS_Tree_Joined' is invalid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Hint 'noexpand' on object 'View_CMS_Tree_Joined' is invalid.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +392
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +815
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4515
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
System.Data.SqlClient.SqlDataReader.get_MetaData() +138
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6738869
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +6741487
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +586
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +107
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +180
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +21
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +325
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +420
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +278
CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) +261
[Exception:
[DataConnection.HandleError]:
Query:
SELECT [NodeAliasPath], [DocumentURLPath], [NodeID], [DocumentCulture]
FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON V.NodeSKUID = S.SKUID
WHERE (NodeSiteID = 1) AND ([DocumentURLPath] LIKE #DocumentURLPath OR [DocumentURLPath] LIKE #DocumentURLPath1)
Caused exception:
Hint 'noexpand' on object 'View_CMS_Tree_Joined' is invalid.
]
CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, Exception ex) +181
CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) +776
CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query) +383
CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query) +401
CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query, Int32& totalRecords) +75
CMS.DataEngine.DataQueryBase`1.GetDataFromDBInternal() +143
CMS.DataEngine.DataQueryBase`1.GetDataFromDB() +96
CMS.DataEngine.DataQueryBase`1.GetData() +149
CMS.DataEngine.DataQueryBase`1.get_Result() +114
CMS.DataEngine.ObjectQueryBase`2.GetResults(IDataQuery query, Int32& totalRecords) +41
CMS.DataEngine.DataQueryBase`1.GetDataFromDB() +128
CMS.DocumentEngine.DocumentQueryBase`2.<GetDataFromDB>b__2() +9
CMS.DocumentEngine.DocumentQueryProperties.GetDataInternal(IDocumentQuery query, Func`1 baseGetDataMethod, Action`1 setTotalRecords) +91
CMS.DataEngine.DataQueryBase`1.GetData() +149
CMS.DataEngine.ObjectQueryBase`2.GetData() +273
CMS.DocumentEngine.DocumentQueryBase`2.GetData() +171
CMS.DataEngine.DataQueryBase`1.get_Result() +114
CMS.DataEngine.DataQueryBase`1.GetResults(IDataQuery query, Int32& totalRecords) +32
CMS.DataEngine.DataQueryBase`1.GetDataFromDB() +128
CMS.DocumentEngine.MultiDocumentQueryBase`3.<GetDataFromDB>b__2() +9
CMS.DocumentEngine.DocumentQueryProperties.GetDataInternal(IDocumentQuery query, Func`1 baseGetDataMethod, Action`1 setTotalRecords) +91
CMS.DataEngine.DataQueryBase`1.GetData() +149
CMS.DataEngine.DataQueryBase`1.get_Result() +114
CMS.URLRewritingEngine.CMSDocumentRouteHelper.RegisterDocumentRoutes(String where, String siteName, List`1 routes) +525
CMS.URLRewritingEngine.CMSDocumentRouteHelper.RegisterRoutes(String siteName) +206
CMS.URLRewritingEngine.CMSDocumentRouteHelper.EnsureRoutes(String siteName) +252
CMS.URLRewritingEngine.URLRewritingHandlers.AuthorizeRequest(Object sender, EventArgs e) +271
CMS.Base.AbstractHandler.CallEventHandler(EventHandler`1 h, TArgs e) +117
CMS.Base.AbstractHandler.Raise(String partName, List`1 list, TArgs e, Boolean important) +826
CMS.Base.SimpleHandler`2.RaiseExecute(TArgs e) +142
CMS.Base.SimpleHandler`2.RaiseExecute(TArgs e) +214
CMS.Base.SimpleHandler`2.StartEvent(TArgs e) +300
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
In Kentico 9 View_CMS_Tree_Joined is indexed, but in Kentico 8, it isn't. So you need to check that this view has indexes. If not, try no create them:
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET NUMERIC_ROUNDABORT OFF
GO
/****** Object: Index IX_View_CMS_Tree_Joined_ClassName_NodeSiteID_DocumentForeignKeyValue_DocumentCulture] ******/
CREATE NONCLUSTERED INDEX [IX_View_CMS_Tree_Joined_ClassName_NodeSiteID_DocumentForeignKeyValue_DocumentCulture] ON [dbo].[View_CMS_Tree_Joined]
(
[ClassName] ASC,
[NodeSiteID] ASC,
[DocumentForeignKeyValue] ASC,
[DocumentCulture] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE UNIQUE CLUSTERED INDEX [IX_View_CMS_Tree_Joined_NodeSiteID_DocumentCulture_NodeID] ON [dbo].[View_CMS_Tree_Joined]
(
[NodeSiteID] ASC,
[DocumentCulture] ASC,
[NodeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

I am getting below Stack Trace when I generate a report. Report has been design with RDLC and it is connect with XSD file. XSD file generate query with SQL Stored Procedure. This report works perfectly but suddenly it get generate the above error. Dot Net Frame work I used here is 2.0 *****************
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2843
System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo) +277
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +594
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +127
System.Data.SqlClient.SqlDataReader.get_MetaData() +112
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6340468
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6341537
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +424
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +211
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +19
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +221
System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +579
System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +181
CSAccCustomerLedgerCurrencyWiseTableAdapters.CUSTOMER_RECEIPTTableAdapter.Fill(CUSTOMER_RECEIPTDataTable dataTable, String STARTCODE, String ENDCODE, Nullable`1 INDATE, Nullable`1 TODATE) +827
Admin_ReportV.LoadCSAccCustomerCurrencyWiseReporting_RECEIPT(DateTime InToday, String StartCode, String EndCode, DateTime asOfDate, DateTime todate) +257
Admin_ReportV.GetReportDatasource(LocalReport InLocalReport, String InReportName, DataSet InDataset, String FilterKey, Dictionary`2 values) +21220
Admin_ReportV.loadCustomerCurrWiseReport(String filename, DataSet ds, Dictionary`2 values, String FilterKey) +405
Admin_ReportV.generateCustomerCurrWise(String AsOfDate, String fromcuscode, String tocuscode, String todate) +253
Admin_ReportV.btnGenerate_Click(Object sender, EventArgs e) +4150
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
I think the reason is due to large number of data in that specific report in that case just add this line in ReportViewer.aspx.cs page
adapter.SelectCommand.CommandTimeout = 0;
but if you are having large amount of data it will take some time but it will work

SqlException when updating cloud service on Azure

I am noticing a lot of semaphore time-outs (see below for full exception) when deploying an update to our Windows Azure Cloud Service.
We have implemented retry logic (and can see the exception is happening within the retry encapsulation) so I'm thinking it is probably a logical issue however I have not been able to find any related instances on the internet, nor factor my own solution!
My question is: Is there a way to handle this? For example can we somehow push all users on to a single instance and update the other? -currently we have two instances running at a minimum.
Here's the full exception:
[SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction):0
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose):0
System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error):0
System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync():0
System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket():0
System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer():0
System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value):0
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady):0
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData():0
System.Data.SqlClient.SqlDataReader.get_MetaData():0
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString):0
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite):0
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite):0
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method):0
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method):0
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior):0
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult):0
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries):0
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query):0
System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression):0
System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source):0
Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func):0
TimeClock.TimeClockService.GetEmployees(String _apiKey, String _authenticationToken, DateTime _lastSync):0
Seems this is a known issue with a VIP swap, even with a SQL Retry strategy and hard-coded machine keys.
User reports of this issue on MSDN
Stack Overflow answer on another thread

MVC EF5 Framework Initialize Database Error

I am using EF 5 and MVC 4.
After I first deploy the project (using web deploy) and the website is launched, my database is automatically created and I can see that the simplemembership tables are created. All my other tables are not. The simplemembership tables and my tables are combined into one DB. I did not use two separate DBs. This works fine in my development environment.
When I go to a controller that lists another table's data (not part of simplemembership) I receive the following error:
[SqlException (0x80131904): There is already an object named 'UserProfile' in the database.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout) +2755286
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +527
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +290
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement) +247
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements) +202
System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements) +19
System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration) +472
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) +175
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) +19
System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context) +150
System.Data.Entity.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c) +97
System.Data.Entity.Internal.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6() +23
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +225
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +208
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +235
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +36
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +21
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +62
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +446
System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
ProofPixModels.Controllers.SubscriberController.Index() in SubscriberController.cs:21
lambda_method(Closure , ControllerBase , Object[] ) +43
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +15
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +15
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +120
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +452
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +32
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +230
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +14
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
There are obviously two InitializeDatabase commands going on here, but I cannot figure out why the clash over this one table. Any help would be greatly appreciated.
Same as above, if you have already run an asp-net membership script table, you will need to clean this up by dropping all these other auto-gen tables. Once you do that you can run the command update-database -verbose and you will see it create the UserProfile table no problem.
I discovered that the problem was caused in the migrations file. One of my models included a collection of UserProfile(s) so this made EF create a Foreign Key which seems to force EF to write code to create the table. It is unaware that the simplemembership will do this for this table apparently.
Anyway I solved the problem by commenting out the create UserProfile table block in the migrations folder. I did make sure to replace it with an AddForeignKey method to keep the relationship intact.
Not sure this is the correct way, but it worked.
This would also happen if you already have asp-net membership tables created earlier, which tries to prevent you from accidentally loosing the credentials for all users.
Drop those tables and views and this error goes away.
Had same issue then manually edited the Initialmigration script with drop table UserProfile at top and executed Update-Database -Verbose. Failed as there is n foreign key constraint. Went to my local db deleted UserProfile table with all tables having foreign keys to that. Executed the migration and table created.

SubSonic 3.0.0.3 | SimpleRepository - OrderByDescending and .First()

this codes works fine on SQL Express 2008:
return _repository.GetInstructions()
.Where(x => x.PublishedDate != null)
.OrderByDescending(x => x.PublishedDate)
.First();
but when run using SQL Server 2000 , it breaks.
here is the error. I'll post the trace if someone wants to see it.
FailedSystem.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '('.
Here's the trace:
TestSqlITInstructionRepository.Should_Get_Latest_ITInstruction : FailedSystem.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '('.
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.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
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.ExecuteReader(CommandBehavior behavior)
at SubSonic.DataProviders.DbDataProvider.ExecuteReader(QueryCommand qry) in DbDataProvider.cs: line 137
at SubSonic.Linq.Structure.DbQueryProvider.Execute<T>(QueryCommand`1 query, Object[] paramValues) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\DbQueryProvider.cs: line 280
at lambda_method(ExecutionScope )
at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\DbQueryProvider.cs: line 131
at SubSonic.Linq.Structure.QueryProvider.System.Linq.IQueryProvider.Execute<S>(Expression expression) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\QueryProvider.cs: line 45
at System.Linq.Queryable.First<TSource>(IQueryable`1 source)
at Kiss.Test.Repositories.TestSqlITInstructionRepository.Should_Get_Latest_ITInstruction() in TestSqlITInstructionRepository.cs: line 73
I don't think SubSonic fully supports MS SQL 2000.
My own findings indicate that .First() genarates TOP (1)
For MS SQL 2000 it should be TOP 1 with no parenthesis
The SubSonic docs (http://subsonicproject.com/docs/Supported_Databases) says that it supports "SQL Server (200-2008)", so that means it's probably a bug. I think you should probably submit it as an issue to the SubSonic github site.

Resources