Entity Framework : Schema specified is not valid - sql-server

I am developing a web application that is using Entity Freamwork 5 Visual Studio 2012 and it need to support both SQL Server and Oracle database providers. I created entity model for Oracle Database. I thought it would work after some changes in connectionstrings, bu no it is not that easy .. I found this post:
http://www.codeproject.com/Articles/82017/Preparing-an-Entity-Framework-model-for-multi-prov
Now I am getting following error
Schema specified is not valid. Errors: my_s_entity.ssdl(2,12) :
warning 0005: Could not find schema information for the attribute
'Version'. my_s_entity.ssdl(2,2) : error 0010: The element Edmx in
namespace http://schemas.microsoft.com/ado/2009/11/edmx was unexpected
for the root element. The expected Schema in one of the following
namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl,
http://schemas.microsoft.com/ado/2009/02/edm/ssdl,
http://schemas.microsoft.com/ado/2009/11/edm/ssdl.
Stack trace:
[MetadataException: Schema specified is not valid. Errors:
my_s_entity.ssdl(2,12) : warning 0005: Could not find schema information for the attribute 'Version'.
my_s_entity.ssdl(2,2) : error 0010: The element Edmx in namespace http://schemas.microsoft.com/ado/2009/11/edmx was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl, http://schemas.microsoft.com/ado/2009/02/edm/ssdl, http://schemas.microsoft.com/ado/2009/11/edm/ssdl.]
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +965
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
I have searched on web but not able to find any solution. Why I am getting this issue? If anyone have every faced same and have any solution please share.

Add a project reference to EntityFramework.SqlServer.dll

I had this error, This solution works for me
public MyContext : DbContext
{
public MyContext() : base("name=MyContext")
{
// the terrible hack
var ensureDLLIsCopied =
System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}

If you open Your edmx file in the xml editor it should look like this:
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<edmx:Runtime>
<edmx:StorageModels>
<Schema Namespace="XXX.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
There is a relationship between the xmlns namespace and the Version of EF you are using. There is some mismatch in the EF Version you created the model With and where you are trying to use it.

Related

How to use Hangfire in ASP.NET Core with Azure database and Active Directory Password authentication

We're trying our first use of Hangfire (v1.7.19) in an ASP.NET Core WebApi application (.NET 5). Previously they've all been old school ASP.NET, and have worked without issue.
Hangfire packages used (per the Hangfire documentation) are Hangfire.Core, Hangfire.SqlServer and Hangfire.AspNetCore. We've also tried to just use the combined Hangfire package, but are having the same results.
Lifting directly from the code on that documentation page, in ConfigureServices we add
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(connectionString), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
DisableGlobalLocks = true
}));
which, at runtime, gives
System.ArgumentException
HResult=0x80070057
Message=Keyword not supported: 'authentication'.
Source=System.Data.SqlClient
StackTrace:
at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Hangfire.SqlServer.SqlServerStorage.<.ctor>b__6_0()
at Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection()
at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](DbConnection dedicatedConnection, Func`2 func)
at Hangfire.SqlServer.SqlServerStorage.UseConnection(DbConnection dedicatedConnection, Action`1 action)
at Hangfire.SqlServer.SqlServerStorage.Initialize()
at Hangfire.SqlServer.SqlServerStorage..ctor(String nameOrConnectionString, SqlServerStorageOptions options)
at Hangfire.SqlServer.SqlServerStorage..ctor(String nameOrConnectionString)
at Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(IGlobalConfiguration configuration, String nameOrConnectionString)
The value of connectionString is
Initial Catalog=XXX;Data Source=YYY;Authentication=Active Directory Password;UID=ZZZ;PWD=PPP"
This works fine with local SqlServer and LocalDb, but not with AzureDB. The connection string is exactly the one we're also using for EntityFrameworkCore 5 (in fact, the value is assigned from context.Database.GetConnectionString()).
I've read where there were issues with AzureDB and .NET Core, but those were resolved quite some time ago. Looking through the Hangfire.SqlServer package dependencies, I see where it uses System.Data.SqlClient, and current documentation for AzureDB use all refer to Microsoft.Data.SqlClient, which makes me think that the enhancements to support Active Directory Password authentication weren't made in System.Data.SqlClient but only in the newer Microsoft.Data.SqlClient package. If that's the case, I can put in a request that Hangfire replace its SqlClient package, but want to get confirmation before I do that.
Any ideas if this is indeed the case? Is there something we can do in the meantime to fix this instead?
Thanks in advance.
Hangfire IO GitHub Issue 1827
Pointers from Sergey Odinokov
As early as 1.7.8 there has been support to use an overload of UseSqlServerStorage that accepts a Func<DbConnection> instead of a connection string where you can use a connection factory to provide the newer Microsoft.Data.SqlClient.SqlConnection which supports the Authentication keyword.
Here is the related source code
You can use this like
services.AddHangfire(config => config
// other options you listed above removed for brevity
.UseSqlServerStorage(
() => new Microsoft.Data.SqlClient.SqlConnection(<connection_string>)
, new SqlServerStorageOptions() {...}
)
);

DDRMenu - Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc

We have tried to upgrade dnn site from v7.3.2 to v8.0.3 but the upgrade was failed and while rolling back the changes the DDRmenu disappeared and the logger shows. The specified dll is present in the bin folder. Can anyone help us?
[ERROR] DotNetNuke.Services.Exceptions.Exceptions -
System.NullReferenceException: Object reference not set to an instance
of an object. at DotNetNuke.Web.Razor.RazorEngine.Render[T](TextWriter
writer, T model) [ERROR] DotNetNuke.Services.Exceptions.Exceptions -
System.InvalidOperationException: Could not locate Razor Host Factory
type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc at
System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(String
typeName) at
System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey
key, Func2 valueFactory) at
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup
config, String virtualPath, String physicalPath) at
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String
virtualPath, String physicalPath)
How did you roll back? You should have reverted to the old version of the database and the old files. Did you delete all of the files before restoring?

Elmah.MVC - MVC 5 ArgumentNullException: Value cannot be null. Parameter name id:

I am receiving an error when trying to render the elmah error logs and using SQL DB. "http://localhost:5525/elmah" [ArgumentNullException: Value cannot be null.
Parameter name: id]
Elmah.ErrorLogEntry..ctor(ErrorLog log, String id, Error error) in c:\builds\ELMAH-1.2-SP2\src\Elmah\ErrorLogEntry.cs:57
Elmah.SqlErrorLog.ErrorsXmlToList(XmlReader reader, IList errorEntryList) in c:\builds\ELMAH-1.2-SP2\src\Elmah\SqlErrorLog.cs:365
Elmah.SqlErrorLog.ErrorsXmlToList(String xml, IList errorEntryList) in c:\builds\ELMAH-1.2-SP2\src\Elmah\SqlErrorLog.cs:332
Elmah.SqlErrorLog.GetErrors(Int32 pageIndex, Int32 pageSize, IList errorEntryList) in c:\builds\ELMAH-1.2-SP2\src\Elmah\SqlErrorLog.cs:186
Elmah.ErrorLogPage.OnLoad(EventArgs e) in c:\builds\ELMAH-1.2-SP2\src\Elmah\ErrorLogPage.cs:76
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
I have the latest Core Elmah 1.2-SP2 and the latest Elmah.MVC 2.1.2. I installed the Nuget package Elmah.MVC with default web.config settings.
When I configure web.config to log errors to the database the errors are recorded in the database but I can't render the error page. When I don't configure the database the elmah page renders just fine.
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Company" />
</elmah>
Decompiling Elmah I see in the constructor where the argument is thrown.
if (id == null)
throw new ArgumentNullException("id");
if (id.Length == 0)
throw new ArgumentException((string) null, "id");
All my ErrorId's in the database are populated GUIDs.
I am stumped as to what id is not being passed to the core elmah. Has anyone ran into this before?
I downloaded the core Elmah code and stepped through to find in SqlErrorLog.cs, method ErrorsXmlToList(XmlReader reader, IList errorEntryList) there is a call to get id which was the parameter missing: string id = reader.GetAttribute("errorId"); I lower cased "errorid" and everything worked. Obviously this is not a good solution because this is core code that everyone works with so I dug deeper.
This led me to look at stored procedure ELMAH_GetErrorsXml. I found in our database we had a lower case "errorid". I updated the stored procedure to select "errorId" and changed the core Elmah back to the original code and of course everything worked.

Silverlight unit testing. Error while running tests

I'm using VS2010. Silverlight 4, NUnit 2.5.5, and TypeMock
TypemockIsolatorSetup6.0.3.619.msi
In the test project MVVM is implemented, PeopleViewModel is a ViewModel which I want to test.
Please advise if you use other products for unit testing of MVVM Silverlight. Or please help to win this TypeMock. TIA
This is the code of the test:
[Test]
[SilverlightUnitTest]
public void SomeTestAgainstSilverlight()
{
PeopleViewModel o = new PeopleViewModel();
var res = o.People;
Assert.AreEqual(15, res.Count());
}
While running the test in ReSharper i get the following error:
TestA.SomeTestAgainstSilverlight : Failed******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
TEST RESULTS:
---------------------------------------------
System.MissingMethodException : Method not found: 'hv TypeMock.ArrangeActAssert.Isolate.a(System.Delegate)'.
at a4.a(ref Delegate A_0)
at a4.a(Boolean A_0)
at il.b()
at CThru.Silverlight.SilverlightUnitTestAttribute.Init()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at Tests.TestA.SomeTestAgainstSilverlight() in TestA.cs: line 21
While running test in NUnit i get:
Tests.TestA.SomeTestAgainstSilverlight:
System.DllNotFoundException : Unable to load DLL 'agcore': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at MS.Internal.XcpImports.Application_GetCurrentNative(IntPtr context, IntPtr& obj)
at MS.Internal.XcpImports.Application_GetCurrent(IntPtr& pApp)
at System.Windows.Application.get_Current()
at ViewModelExample.ViewModel.ViewModelBase.get_IsDesignTime() in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\ViewModelBase.cs:line 20
at ViewModelExample.ViewModel.PeopleViewModel..ctor(IServiceAgent serviceAgent) in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\PeopleViewModel.cs:line 28
at ViewModelExample.ViewModel.PeopleViewModel..ctor() in C:\Documents and Settings\USER\Desktop\ViewModelExample\ViewModelExample\ViewModel\PeopleViewModel.cs:line 24
at Tests.TestA.SomeTestAgainstSilverlight() in C:\Documents and Settings\USER\Desktop\ViewModelExample\Tests\TestA.cs:line 22
UPDATE: I'm not following the question. I've switched to other tools.
This message looks like a mismatched files issue. Try creating a new test project from scratch.
Start by adding references to Typemock.dll and Typemock.ArrangeActAssert.dll. From the CThru directory add both CThru.dll and CThru.Silverlight.dll.
Add a reference to System.Windows (located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll).
Try creating a new test method, and decorate it with SilverlightUnitTest attribute:
using NUnit.Framework;
using CThru.Silverlight;
[TestFixture]
public class SilverlightTest
{
[Test, SilverlightUnitTest]
public void EmptyTest()
{
}
}
Run this empty test. If you're still having the problem you described, please contact support at typemock.com for further assistance.

Need help for IBatis?

I am using IBatis for my applicaiton. I am using IBatis 1.6.1 version.I thought it can handle all operations related to DB connections. But I am having little bit concern about this now. Sometimes I am getting the following error details to my log file,
Message
Unable to open connection to "MySQL, MySQL provider 5.0.8.1".
Source
IBatisNet.DataMapper
Stack
at IBatisNet.DataMapper.SqlMapSession.OpenConnection(String connectionString) at IBatisNet.DataMapper.SqlMapSession.OpenConnection() at IBatisNet.DataMapper.Commands.DbCommandDecorator.System.Data.IDbCommand.ExecuteReader() at IBatisNet.DataMapper.MappedStatements.MappedStatement.RunQueryForObject(RequestScope request, ISqlMapSession session, Object parameterObject, Object resultObject) at IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObject(ISqlMapSession session, Object parameterObject, Object resultObject) at IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObject(ISqlMapSession session, Object parameterObject) at IBatisNet.DataMapper.SqlMapper.QueryForObject(String statementName, Object parameterObject) at Sunya.VideoStreaming.Persistence.SchoolRepository.GetSchoolDetailsByUrl(String SchoolUrl) in D:\SVN\Sprint104\Persistence\SchoolRepository.cs:line 192 at EduVisionBasePage.GetSchoolUrl(School& _school) at ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Message
Too many connections
Source
MySql.Data
Stack
at MySql.Data.MySqlClient.MySqlStream.OpenPacket() at MySql.Data.MySqlClient.NativeDriver.Authenticate411() at MySql.Data.MySqlClient.NativeDriver.Authenticate() at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at IBatisNet.DataMapper.SqlMapSession.OpenConnection(String connectionString)
Does someone has some idea about the error?
iBATIS has been around for quite a while (2001), and I have my doubts that there's a major bug in the MySQL provider. You mentioned that the error occurs "sometimes" - if it's intermittent, perhaps the problem lies elsewhere. "Unable to open connection" is likely to mean just that. Network errors, database outages, too many unreleased connections, authentication issues, etc. might all cause this error.
If you are using the JDBC transaction manager set the datasource to 'UNPOOLED' in you myBatisConfig.xml
<transactionManager type="JDBC"/>
<dataSource type="UNPOOLED">
.
.
.
</dataSource>
</environment>
That is the short answer. My hunch is The connection pool class is holding connections too long. Lowering the values for 'poolMaximunActiveConnection' and 'poolMaximunIdleConnections' may solve the problem.
Notes: using myBatis 3.0.3 Java, mySql Windows 5.5.9
search terms: iBatis, myBatis, 'Too many connections', mySQL

Resources