Npgsql error - The store type 'nvarchar(MAX)' could not be found in the Npgsql provider manifest - npgsql

I'm new to Postgres and using npgsql as the provider to EF6. Just to provide some context, I've recently migrated our SQL Server to Aurora Postgres using the AWS DMS. That seems to be all good; I can see data and tables, etc...Now, I'm trying to hook up our application (in C# using EF6) to switch over to the Postgres DB. I've gone through all the steps to setup npgsql and npgsql EF provider, and making a new additional db context to connect to the Postgres DB. All seems good at this point.
I decided to do a simple EF query to fetch.
var courses = context.Courses.FirstOrDefault();
I got this exception:
An Internal Server Error has occurred|System.InvalidOperationException: The store type 'nvarchar(MAX)' could not be found in the Npgsql provider manifest
at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty column, EntityType table, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass47_0.<Configure>b__0(Tuple`2 pm)
at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride)
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride)
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, ICollection`1 entitySets, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source)
Anyone know what this means?

Take a look at these EF docs on how to manage migrations with multiple databases.

Related

SSMS Collation conflict when expand Tables

some strange SSMS behaviour annoyed me for the last few days.
I'm using EF Core 5 Code First and trying to create a test database with EnsureCreated(). The code runs fine and database appears on my local server. But when I try to expand Tables in SSMS I get following error:
I'm using mssql docker container which is configured for German language (MSSQL_LCID: 1031).
Also, we have production database dumps that I can restore on my local machine and get everything work fine.
Here are default server and database collation which I found in properties:
server: SQL_Latin1_General_CP1_CI_AS
database from dump: Latin1_General_CI_AS
database from EnsureCreated(): Latin1_General_CI_AS
So as you see collations for each databases are the same. But I don't get conflict on restored one!
UPDATE:
Here are some details of error (retrieved by clicking Show details button)
===================================
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
------------------------------
For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object connectionInfo, Request request)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.NavigableItemBuilderDataReader.RunQuery()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.NavigableItemBuilderDataReader.Process()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.NavigableItemBuilderDataReader.get_PropertyNames()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.BuildDynamicItemWithQuery(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, String urnQuery, Boolean registerBuilder, Boolean registerBuiltItems)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.BuildDynamicItem(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, IFilterProvider filter)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.Build(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, IFilterProvider filter)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NonContextFilterNavigableItemBuilder.Build(IList`1 targetList, INodeInformation source, INavigableItem sourceItem, IFilterProvider filter)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItem.RequestChildren(IGetChildrenRequest request)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ExplorerHierarchyNode.BuildChildren(WaitHandle quitEvent)
===================================
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Common.ServerConnection.GetExecuteReader(SqlCommand command)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteReader(String sqlCommand, SqlCommand& command)
at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataReader(String query, SqlCommand& command)
at Microsoft.SqlServer.Management.Smo.DataProvider.SetConnectionAndQuery(ExecuteSql execSql, String query)
at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetDataProvider(StringCollection query, Object con, StatementBuilder sb, RetriveMode rm)
at Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillData(ResultType resultType, StringCollection sql, Object connectionInfo, StatementBuilder sb)
at Microsoft.SqlServer.Management.Smo.SqlObjectBase.FillDataWithUseFailure(SqlEnumResult sqlresult, ResultType resultType)
at Microsoft.SqlServer.Management.Smo.SqlObjectBase.BuildResult(EnumResult result)
at Microsoft.SqlServer.Management.Smo.SqlObjectBase.GetData(EnumResult erParent)
at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData()
at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData(Request req, Object ci)
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object connectionInfo, Request request)
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object connectionInfo, Request request)
===================================
Ein Sortierungskonflikt zwischen "Latin1_General_CI_AS" und "SQL_Latin1_General_CP1_CI_AS" im UNION ALL-Operator, der in der 2-Spalte der SELECT-Anweisung auftritt, kann nicht aufgelöst werden.
Die Sicht oder Funktion "sys.all_columns" konnte aufgrund von Bindungsfehlern nicht verwendet werden. (.Net SqlClient Data Provider)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=14.00.3411&EvtSrc=MSSQLServer&EvtID=451&LinkId=20476
------------------------------
Server Name: localhost
Error Number: 451
Severity: 16
State: 1
Procedure: all_columns
Line Number: 2
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ServerConnection.GetExecuteReader(SqlCommand command)
Seems like it comes from view all_columns. I also can't do any select from this system view nor event see its columns.

Scaffold-DbContext throw ArgumentNullException

I get the following exception when I try to scaffold one of our databases.
For foreign key FK_ActivityEvent_ActivityCode on table dbo.ActivityEvent, unable to find the column called UniqActivityCode on the foreign key's principal table, dbo.ActivityCode. Skipping foreign key.
For foreign key FK_Line_Line on table dbo.Line, unable to find the column called UniqLine on the foreign key's principal table, dbo.Line. Skipping foreign key.
For foreign key FK_MarketingLine_MarketingLine on table dbo.MarketingLine, unable to find the column called UniqMarketingLine on the foreign key's principal table, dbo.MarketingLine. Skipping foreign key.
System.ArgumentNullException: Value cannot be null.
Parameter name: column
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetPropertyName(DatabaseColumn column)
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitPrimaryKey(EntityTypeBuilder builder, DatabaseTable table)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String namespace, String language, String contextDir, String contextName, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: column
I successfully scaffolded one of our databases so I'm sure I'm using the scaffold command properly. Also, I can access the database using the connection string I entered on the Scaffold-DbContext command.
I installed the following packages:
install-package microsoft.entityframeworkcore.sqlserver
install-package microsoft.entityframeworkcore.tools
Using .NET Core Console App 2.1 on Windows 10.
Not sure if this is related but I get the following message when I try to expand the Database Diagrams in ssms. (I don't get this message on the other database that I successfully scaffolded)

Error using installing MSSQL Server2014 using chef

I have window 2012 R2 based two VM machines.
One is using for Chef-workstation and other is for Chef-client.
I am trying to install MSSQL Server 2014 using chef-cmd from chef-workstation on chef-client.
Sometimes I am getting below error on chef-client while installing MSSQL Server.
check for instance name, got: 'MSSQLSERVER' Error: Action
"Microsoft.SqlServer.Configuration.SetupExtension.FinalCalculateSettingsAction"
threw an exception during execution.
Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException:
There was an error generating the XML document. --->
Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException:
There was an error generating the XML document. --->
System.InvalidOperationException: There was an error generating the
XML document. --->
System.Security.Cryptography.CryptographicException: Access is denied.
at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData,
Byte[] optionalEntropy, DataProtectionScope scope) at
Microsoft.SqlServer.Common.SqlSecureString.WriteXml(XmlWriter writer)
at
System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable
serializable, String name, String ns, Boolean isNullable, Boolean
wrapped) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write6_AgentConfigurationPublic(String
n, String ns, AgentConfigurationPublic o, Boolean isNullable, Boolean
needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write7_AgentConfigurationPublic(Object
o) at
Microsoft.SqlServer.Setup.Chainer.Workflow.ActionEngine.RunActionQueue()
Error: Action
"Microsoft.SqlServer.Configuration.BootstrapExtension.ExecuteWorkflowAction"
threw an exception during execution.
Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException:
There was an error generating the XML document. --->
Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException:
There was an error generating the XML document. --->
System.InvalidOperationException: There was an error generating the
XML document. --->
System.Security.Cryptography.CryptographicException: Access is denied.
at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData,
Byte[] optionalEntropy, DataProtectionScope scope) at
Microsoft.SqlServer.Common.SqlSecureString.WriteXml(XmlWriter writer)
For more information:
https://discourse.chef.io/t/error-action-microsoft-sqlserver-configuration-setupextension-finalcalculatesettingsaction-threw-an-exception-during-execution/13778

MSSQL 2016 Package execution failed | SSIS error: Index was out of range

I've made a copy job with Copy Database Wizard using SMO(leave DB online). The DB is to be copied to the same SQL instance. This fails with
The package execution failed. The step failed.
If I execute the SSIS package it has created, the following occurs:
Event Name: OnError Message: Index was out of range. Must be
non-negative and less than the size of the collection. Parameter name:
index StackTrace: at System.Collections.BitArray.Set(Int32 index,
Boolean value) at
Microsoft.SqlServer.Management.Smo.PermissionWorker.GetPermissionSetBase(PermissionEnumKind
kind, Int32 i) at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetPermissionsFromCache(PermissionEnumKind
kind) at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.AddScriptPermissions(StringCollection
sc, PermissionEnumKind kind, ScriptingPreferences sp) at
Microsoft.SqlServer.Management.Smo.Database.AddScriptPermission(StringCollection
query, ScriptingPreferences sp) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateSpecialUrn(Urn
urn, ScriptingPreferences sp, ObjectScriptingType& scriptType) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreate(Urn urn,
ScriptingPreferences sp, ObjectScriptingType& scriptType) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateObjects(IEnumerable1
urns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptUrns(List1
orderedUrns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable1
urns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List1
urns, ISmoScriptWriter writer) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.Script(UrnCollection
list, ISmoScriptWriter writer) at
Microsoft.SqlServer.Management.Smo.DataTransferBase.GetScriptLoadedTransferWriter()
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData() at
Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
I have tried starting the job from SQLCMD as well. Same results.
I have tried Detach/Attach method as well. That went through fine, however, that is not a desired option as it leaves the DB offline for the transfer's duration.
I have admin rights on the server(Windows) and the instance as well.
Executing the package(.dtsx file using Package Execution Utility) outside SSMS gives the same error.
I have created an empty database with only one table in it. Same error happens.
Please help..
OS: Windows Server 2012
MSSQL: 2016 SP1
This has been resolved with applying the January 2018 CU, even though this fix is NOT documented there.

Generate SQL scripts from Azure SQL Database

When I tried to Generate scripts in SQL Server Management Studio 2012 from my Azure database. I received following error:
Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptPublishException:
An error occurred while scripting the objects. --->
Microsoft.SqlServer.Management.Sdk.Sfc.EnumeratorException: Failed to
retrieve data for this request. --->
Microsoft.SqlServer.Management.Sdk.Sfc.InvalidVersionEnumeratorException:
Operation not supported on version 11.0 SqlAzureDatabase. at
Microsoft.SqlServer.Management.Smo.XmlReadDoc.LoadFile(Assembly a,
String strFile) at
Microsoft.SqlServer.Management.Smo.SqlObject.LoadInitData(String file,
ServerVersion ver, DatabaseEngineType databaseEngineType) at
Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.LoadElement(ObjectLoadInfo
oli, ServerVersion ver, DatabaseEngineType databaseEngineType) at
Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.GetElement(ObjectLoadInfo
oli, ServerVersion ver, DatabaseEngineType databaseEngineType) at
Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.GetAllElements(Urn
urn, ServerVersion ver, DatabaseEngineType databaseEngineType, Object
ci) at
Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetObjectsFromCache(Urn
urn, Object ci) at
Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData(Request
req, Object ci) at
Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object
connectionInfo, Request request) at
Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object
connectionInfo, Request request) --- End of inner exception stack
trace --- at
Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object
connectionInfo, Request request) at
Microsoft.SqlServer.Management.Smo.ExecutionManager.GetEnumeratorData(Request
req) at
Microsoft.SqlServer.Management.Smo.Server.GetLCIDCollation(String
collationName) at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetComparerFromCollation(String
collationName) at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetDbComparer(Boolean
inServer) at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitializeStringComparer()
at Microsoft.SqlServer.Management.Smo.Database.PreInitChildLevel() at
Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitChildLevel(Urn
levelFilter, ScriptingPreferences sp, Boolean forScripting) at
Microsoft.SqlServer.Management.Smo.DatabasePrefetchBase.InitializeObjectCollection(String
type) at
Microsoft.SqlServer.Management.Smo.DatabasePrefetchBase.d__1.MoveNext()
at
Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.SfcChildrenDiscovery(HashSet1
discoveredUrns) at
Microsoft.SqlServer.Management.Smo.SmoDependencyDiscoverer.Discover(IEnumerable1
urns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.Discover(IEnumerable1
urns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable1
urns) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List`1
urns, ISmoScriptWriter writer) at
Microsoft.SqlServer.Management.Smo.ScriptMaker.Script(Urn[] urns,
ISmoScriptWriter writer) at
Microsoft.SqlServer.Management.SqlScriptPublish.SqlScriptGenerator.DoScript(ScriptOutputOptions
outputOptions) --- End of inner exception stack trace --- at
Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object
sender, DoWorkEventArgs e) at
System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at
System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object
argument)
I found this thread: Failed to generate scripts for Sql Azure database: "Getting the list of objects from : failed"
but I cannot use: http://cloudservices.red-gate.com/
Try using third party tools for SQL Server that are able to work with Azure. I think SQL Compare from Red-Gate had the ability to work with SQL Azure but I’m not 100% sure. You can always use it in trial mode to get the job done…
SQL Azure Migration wizard might be an option for you as well.
http://sqlazuremw.codeplex.com/

Resources