I was trying to set the DotNetNuke Content localization, but when I click on enable localized content on language page the progress bar that show up stuck.
I was checking the event log and i noticed that it raises a general exception:
DefaultDataProvider: DotNetNuke.Data.SqlDataProvider,
DotNetNuke.SqlDataProvider ExceptionGUID:
a139c600-71a0-4ee3-a66f-5968bd2bdfde InnerException: Transaction
(Process ID 56) was deadlocked on lock resources with another process
and has been chosen as the deadlock victim. Rerun the transaction.
FileName: FileLineNumber: 0 FileColumnNumber: 0 Method:
System.Data.SqlClient.SqlConnection.OnError StackTrace: Message:
System.Data.SqlClient.SqlException: Transaction (Process ID 56) was
deadlocked on lock resources with another process and has been chosen
as the deadlock victim. Rerun the transaction. at
System.Data.SqlClient.SqlConnection.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.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.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) at
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(SqlConnection
connection, CommandType commandType, String commandText,
SqlParameter[] commandParameters) at
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String
connectionString, CommandType commandType, String commandText,
SqlParameter[] commandParameters) at
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String
connectionString, String spName, Object[] parameterValues) at
DotNetNuke.Data.SqlDataProvider.AddSearchItemWordPosition(Int32
SearchItemWordID, String ContentPositions) at
DotNetNuke.Services.Search.SearchDataStore.AddIndexWords(Int32
indexId, SearchItemInfo searchItem, String language) at
DotNetNuke.Services.Search.SearchDataStore.StoreSearchItems(SearchItemInfoCollection
SearchItems)
It should localize pages in three languages, pt-BR(Main), en-US and es-ES. But it only works on en-US. It succefully localize all the pages in en-US but in es-ES it just does the first page.
Now anytime i try to do some page related activities, as adding a page in the 3 languages, the pages gets bugged and keep rising exceptions when i'm trying to edit it. And the page doesn't show up in es-ES language, only in pt and en. This elimineted all workaround that i could think and couldnt find any solution on web.
There is a bug in the search engine scheduler for DotNetNuke. Disable the scheduler, or increasing the time between scheduler activity to avoid concurrent updates. See this thread. http://forums.asp.net/t/905236.aspx/1
Related
I'm using f# to update a DB from a csv file, so I'm using Fsharp.Data to parse it, and it works well, as intended, and then SqlProvider to do the actual update.
So I get a list of items from my csv and one of the fields is an identifier for the table I'm meaning to update. I come from a c# background so using LINQ I sould do something like this:
var results = context.MyTable.Where(m => myList.Contains(m.Identifier))
and that would give me the rows I'm looking for. I tried to do this
query {
for m in ctx.Dbo.MyTable do
where (List.contains m.Identifier myList)
select m
}
and got this error at runtime:
System.InvalidOperationException: variable 'm' of type 'FSharp.Data.Sql.Common.SqlEntity' referenced from scope '', but it is not defined
at Microsoft.FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation(FSharpExpr e)
at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedInner(CanEliminate canElim, FSharpExpr queryProducingSequence)
at Microsoft.FSharp.Linq.QueryModule.clo#1727-1.Microsoft-FSharp-Linq-ForwardDeclarations-IQueryMethods-Execute[a,b](FSharpExpr`1 q)
at .$FSI_0006.main#()
Stopped due to error
then tried the following
query {
for m in ctx.Dbo.MyTable do
for id in myList do
where (id = m.Identifier)
select m
}
and got this at compile time:
myScript.fsx(291,30): error FS0001: The type 'string list' is not compatible with the type 'System.Linq.IQueryable'
I'm sure this can be done, I'd like to know what am I doing wrong
What is the right way to go about this?
What is it that I'm assuming that is evidently wrong?
Update
I just followed Aaron answer, this is how my code looks now, the relevant part at least:
let ctx = Sql.GetDataContext();
let getZipCodes (zipcodes: string list) =
query {
for zc in ctx.CleanZipCodes do
for id in zipcodes do
where (id = zc.ZipCode)
select zc
}
|> Seq.toList
and now I get this error:
System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. --->
System.Data.SqlClient.SqlException: Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action'1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
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, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource'1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
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.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Objects.ObjectQuery'1.GetResults(Nullable'1 forMergeOption)
at System.Data.Objects.ObjectQuery'1.System.Collections.Generic.IEnumerable.GetEnumerator()
at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable'1 source)
at .$FSI_0006.main#()
The error in your second example seems to be an issue with LINQ to SQL. You can work around it by using the SQL Entity type provider, which is called SqlEntityConnection in the built-in type providers:
#r "System.Data.Entity"
#r "FSharp.Data.TypeProviders"
open Microsoft.FSharp.Data.TypeProviders
type SqlDb = SqlEntityConnection<"...">
let context = SqlDb.GetDataContext()
let myList = [...]
query {
for record in context.MyTable do
for id in myList do
where (id = record.Identifier)
select record
} |> Seq.toList
MiniProfiler is not working too well for me. Even installation was broken, and had to be fixed with the aid of an answer to another question here.
I have two problems below.
I followed all the installation steps on the website.. as follows copying from my code.
These things have been altered (global.asax):
... Application_Start ...
MiniProfilerEF6.Initialize();
....
MiniProfiler.Settings.Results_List_Authorize = IsUserAllowedToSeeMiniProfilerUI;
MiniProfiler.Settings.Results_Authorize = IsUserAllowedToSeeMiniProfilerUI;
...
And this (layout file):
...
#MiniProfiler.RenderIncludes()
</body>
...
Problem 1:
The MiniProfilerEF6.Initialize() call throws an exception.
System.Data.SqlClient.SqlException was unhandled by user code
Message=Invalid object name 'dbo.EdmMetadata'.
StackTrace:
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.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, Boolean describeParameterEncryptionRequest)
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 StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\TeamCity\buildAgent\work\a743336045964cbc\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 246
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
Problem 2:
If I disable the non-working database stuff, viewing the pages for the results (in Chrome) shows nothing. Viewing the results index page gives the following in the Chrome console (404 errors in the networking pane):
results-index:3 GET http://localhost/vll/mini-profiler-resources/includes.js?v=ySF6M98CBehTtL86BbiEmys9yxR1HKazhe2sznfdUWQ=
results-index:4 GET http://localhost/vll/mini-profiler-resources/includes.css?v=ySF6M98CBehTtL86BbiEmys9yxR1HKazhe2sznfdUWQ=
results-index:6 Uncaught ReferenceError: MiniProfiler is not defined(anonymous function) # results-index:6
Why doesn't miniprofiler work as described?
I got the following error while running Update-Database -Verbose:
Using StartUp project 'WebApplication'. Using NuGet project
'WebApplication'. Specify the '-Verbose' flag to view the SQL
statements being applied to the target database. Target database is:
'Frappuccino' (DataSource: (Localdb)\v11.0, Provider:
System.Data.SqlClient, Origin: Configuration). No pending explicit
migrations. Applying automatic migration:
201402032027563_AutomaticMigration. ALTER TABLE [dbo].[Clients] ALTER
COLUMN [ID] [int] NOT NULL System.Data.SqlClient.SqlException
(0x80131904): The object 'PK_dbo.Clients' is dependent on column 'ID'.
The object 'FK_dbo.Users_dbo.Clients_Client_ID' is dependent on column
'ID'. ALTER TABLE ALTER COLUMN ID failed because one or more objects
access this column. at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action1 wrapCloseInAction) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection, Action1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj, Boolean& dataReady) at
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String
methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1
completion, String methodName, Boolean sendToPipe, Int32 timeout,
Boolean asyncWrite) at
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at
System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TInterceptionContext,TResult](Func1
operation, TInterceptionContext interceptionContext, Action1
executing, Action1 executed) at
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand
command, DbCommandInterceptionContext interceptionContext) at
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction
transaction, MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction
transaction, MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1
migrationStatements, DbConnection connection) at
System.Data.Entity.Migrations.DbMigrator.<>c_DisplayClass32.b_2e()
at
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c_DisplayClass1.b_0()
at
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1
operation) at
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action
operation) at
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1
migrationStatements) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1
migrationStatements) at
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String
migrationId, XDocument targetModel, IEnumerable1 operations,
IEnumerable1 systemOperations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String
migrationId, XDocument sourceModel, XDocument targetModel, Boolean
downgrading) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String
migrationId, XDocument sourceModel, XDocument targetModel, Boolean
downgrading) at
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String
targetMigration) at
System.Data.Entity.Migrations.DbMigrator.<>c_DisplayClassc.b_b()
at
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action
mustSucceedToKeepDatabase) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action
mustSucceedToKeepDatabase) at
System.Data.Entity.Migrations.DbMigrator.Update(String
targetMigration) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String
targetMigration) at
System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate
callBackDelegate) at
System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner
runner) at
System.Data.Entity.Migrations.Design.ToolingFacade.Update(String
targetMigration, Boolean force) at
System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c_DisplayClass2.<.ctor>b_0()
at
System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action
command) ClientConnectionId:9854ba62-772c-4ba6-b185-ecae993e065f The
object 'PK_dbo.Clients' is dependent on column 'ID'. The object
'FK_dbo.Users_dbo.Clients_Client_ID' is dependent on column 'ID'.
ALTER TABLE ALTER COLUMN ID failed because one or more objects access
this column.
What I did before this is to change the ID variables from my Code-First Model classes from Int16 to Int32.
Any help please?
It looks like the database can't alter/drop the ID column because another table has a foreign key referencing the ID column. If you drop the reference, update the column, and then re-add the reference, you should be good to go...
PROBLEM SOLVED: After deleting all migration related folders, files and tables, I re enable the Migrations and repopulated the database as you've said
Building on the accepted answer, here are specific steps to work around the issue without dropping all migrations or manually editing one.
In my situation I had
public class Parent
{
public virtual ICollection<Child> A { get; set; }
}
The type for the child had to be changed from Child to OtherChild. That is when I encountered the error.
To work around it, I created two migrations. The first simply unmapped the property A from EF. I could have also commented it out, but quite a bit of code accessing the property would have failed to compile.
public class Parent
{
[NotMapped]
public virtual ICollection<Child> A { get; set; }
}
add-migration UnmapA
update-database
then I re-mapped the property and changed the type
public class Parent
{
public virtual ICollection<OtherChild> A { get; set; }
}
add-migration ChangeChildType
update-database
I experience an error when trying to create a database using the following code.
Note the problem does not happen if the connection string is not passed in.
Also the problem happens when I run the program in the IDE. It does not happen if I run the program .exe or if I run the unit tests within the IDE.
However if the database is created by running the unit tests or by running the .EXE then the __MigrationHistory table is created in the main tables section, not the system tables.
public Context(string connString, bool AddInitialRecords )
: base(connString ?? "MyContextName")
{
this.CheckDatabase(AddInitialRecords);
}
public void CheckDatabase(bool AddInitialRecords)
{
if (this.Database.Exists())
{
// upgrade stuff
}
else
{
Database.Create(); // error occurs here
// seeding stuff
}
}
I don't get the problem if I just use something like
var db1 = new Context();
db1.Database.CreateIfNotExists();
I have found some documentation here but it confuses me. I am installing from a "stable build" surely I aren't experiencing something from 2012? What could I be doing wrong with PM?
The error message for the problem is....
System.Data.Entity.Core.EntityCommandExecutionException occurred
HResult=-2146232004 Message=An error occurred while executing the
command definition. See the inner exception for details.
Source=EntityFramework StackTrace:
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
entityCommand, CommandBehavior behavior) InnerException:
System.Data.SqlClient.SqlException
HResult=-2146232060
Message=Invalid object name 'dbo.__MigrationHistory'.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=208
Procedure=""
Server=.\SQLEXPRESS
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
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)
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.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c__DisplayClassb.b__8()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,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(CommandBehavior
behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
entityCommand, CommandBehavior behavior)
InnerException:
This happens because EF does some probing for the __MigrationsHistory table. For instance you can use EF with an existing database that was not created using EF Migrations but EF has no way of knowing it so it tries to connect to the database and uses the table to check this. If the table does not exist an exception will be thrown. EF then catches the exception and does the right thing (e.g. creates the __MigrationsHistory table if needed or proceeds without using migrations).
In general you won't see this exception when running without the debugger. However when debugging your code AND when the option to break the execution when an exception is thrown is set you will see all the exceptions that are being thrown even if they are internally handled and never reach your code. The default setting is not to break when the exception is thrown but only when an exception that is not being handled is thrown. You can change the setting by checking/unchecking a check box in the "Thrown" column in the Debug -> Exceptions dialog.
In VS 2017 you open exception settings using Debug->Windows->Exception Settings. If you right-click on the "Common Language Runtime Exceptions" you can select the "Restore Defaults" which disables breaking your program when most of the exceptions are thrown.
You can turn off code first database initialization for your database, by adding this to your context's constructor:
System.Data.Entity.Database.SetInitializer<YourContext>(null);
This should prevent the attempt to access dbo.__MigrationHistory.
I faced the same issue. It means that EF is not able to find the __Migration history table. also note for some reason it has to be dbo.__MigrationHistory (note dbo). Ensure that you have run "update-database" atleast once before running the Context
I forgot to add the database name in my connection string. After I added, it started to work
Just uncheck break checkbox then click enable editing to proceed
the database I was using Table __MigrationHistory was missing, so when I Scripted migrations, it generated this code:
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);
END;
and This fixed..
I have followed below steps to create database using code first approach.
Create classes
Launch package manager
Enable-Migrations -ContextTypeName -MyDb
Made change in Model class
execute 'Update-Database -Verbose'
Change was reflected in the database table
Now I connect to the database and delete table. When I am executing 'Update-Database -Verbose' command, my expectation was it will create table again but its failing with below error message.
PM> Update-Database -Force
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending code-based migrations.
Applying automatic migration: 201308221453295_AutomaticMigration.
System.Data.SqlClient.SqlException (0x80131904): Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.
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.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:d07c8463-88f6-44fa-a242-fe0da2c36f31
Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.
Can anyone help? How can I create table again using code first approach?
Regards,
Hemant Shelar
There's a system table in the database that holds all the run migrations, so rerunning Update-Database shouldn't do anything. Unless you've changed your model in your project causing an Automatic Migration, where you haven't explicitly created the migration and Entity Framework is trying to match the database to the models.
As Raphaƫl mentioned, it's code first. You shouldn't be modifying the tables directly if you want to manage it through code first. If you really want to do this, you need to remove the migration from the __MigrationHistory system table so Entity Framework doesn't think the migration has run. Or use the Update-Database -Target:[migration target here] to downgrade/revert a database through the commandlet.