Mysql Connector always get Object reference not set to an instance of an object-Collection of common programming errors
My whole app is simply connect to mysql database and insert data using Entityframework. the code works well locally but when i upload in my amazon server, it just give me this error: you can see at http://fb1.131x.com/test_data.aspx
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. Details: System.NullReferenceException: Object reference not set to an instance of an object.
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:
[NullReferenceException: Object reference not set to an instance of an object.]
MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance() +126
MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(Type serviceType) +39
System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory) +89
System.Data.Metadata.Edm.Loader.InitializeProviderManifest(Action`3 addError) +174
System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader) +301
System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader) +121
System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader) +106
System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader) +49
System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation) +984
System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation) +245
System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +472
System.Data.Metadata.Edm.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) +162
System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer`2& cachedCTypeFunction) +203
System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) +305
System.Data.Metadata.Edm.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) +129
System.Data.Metadata.Edm.MetadataCache.LoadItemCollection(IItemCollectionLoader`1 itemCollectionLoader, T entry) +165
System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken) +245
System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader) +312
System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +802
System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) +11108961
System.Data.EntityClient.EntityConnection.Open() +198
System.Data.Objects.ObjectContext.EnsureConnection() +97
System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) +651
System.Data.Entity.Internal.InternalContext.SaveChanges() +218
test_data.Page_Load(Object sender, EventArgs e) +231
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064
Exception
And I also paste my webconfig, i try to use 6.3.5 and 6.4.4 version, i just get same error.
-
It seems that you did not include the reference for MySql.Data.Entity. Without that dll it wont work
-
These are some of the things u could try. it is always a difficult step to deploy an application on a hosting provider. once it gets going it does get going though.
- a.build clean.
- b.build mysql dll into ur bin directory
- c.Install nuget packages for MySQL.Data and MySQL.Data.Entities.((right click on assembly and ensure Copy Local is set to true before building)
- d.Remove Version=6.3.5.0 tag entirely and build without any versioning on VS.type=”MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data” instead of specifying the full version data.