8

मैं माइग्रेशन को किसी विशिष्ट परिदृश्य के लिए काम नहीं कर सकता।इकाई फ्रेमवर्क माइग्रेशन - गतिशील कनेक्शन स्ट्रिंग के लिए समर्थन

हमारा एप्लिकेशन दो अलग-अलग मॉडल का उपयोग करता है। पहला मुख्य डेटाबेस के लिए है और वहां, माइग्रेशन ठीक काम कर रहा है। दूसरा मॉडल हमारे ग्राहकों के डेटाबेस के लिए है जो प्रत्येक ग्राहक के लिए विशिष्ट हैं (बेशक ...) लेकिन सभी एक ही मॉडल साझा करते हैं।

तो, एप्लिकेशन (एएसपी.नेट एमवीसी 3) में, हम मार्ग का उपयोग कर ग्राहक की पहचान करते हैं और सभी ग्राहकों को उसी एप्लिकेशन में होस्ट किया जाता है। इसलिए, प्रत्येक अनुरोध के लिए हम अपने ग्राहक मॉडल डीबीकॉन्टेक्स्ट कन्स्ट्रक्टर की कुंजी पास करते हैं और उस कुंजी के साथ हम एक सरल सहायक विधि के माध्यम से कनेक्शन स्ट्रिंग को पुनर्प्राप्त करते हैं।

एप्लिकेशन ठीक काम कर रहा है लेकिन माइग्रेशन नहीं है क्योंकि मुझे पैकेज प्रबंधक कंसोल में कुंजी पास करने का कोई तरीका नहीं मिला है।

मैंने अपना खुद का IDbConnectionFactory बनाने की कोशिश की लेकिन इसे ध्यान में नहीं रखा गया है।

अगर मैं कनेक्शन कारखाना मैं निम्न त्रुटि जो सामान्य है के बाद से कोई कुंजी पारित कर दिया है, लेकिन मैं देख सकता हूँ कि मेरे कनेक्शन कारखाना (EFCustomerModel.EFConnectionFactory) में लात है पाने के साथ एक अद्यतन-डेटाबेस आदेश का प्रयास करें:

PM> update-database -verbose 
Using NuGet project 'EFCustomerModel'. 
Using StartUp project 'PMEL.DatabaseSetup'. 
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. 
    at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) 
    at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) 
    at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) 
    at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) 
    at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) 
    at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) 
    at System.Data.SqlClient.SqlConnection..ctor(String connectionString) 
    **at EFCustomerModel.EFConnectionFactory.CreateConnection(String nameOrConnectionString) in C:\...\EFCustomerModel\EFConnectionFactory.vb:line 18** 
    at System.Data.Entity.Internal.LazyInternalConnection.Initialize() 
    at System.Data.Entity.Internal.LazyInternalConnection.get_Connection() 
    at System.Data.Entity.Internal.LazyInternalContext.get_Connection() 
    at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo) 
    at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 
Format of the initialization string does not conform to specification starting at index 0. 

लेकिन जब मैं अपने कुंजी -ConnectionString पैरामीटर का उपयोग करने में पारित करने के लिए प्रयास करते हैं, तो मेरे कनेक्शन कारखाना नजरअंदाज कर दिया है और मैं एक ही त्रुटि मिलती है:

PM> update-database -verbose -ConnectionString:CC99999 -ConnectionProviderName:System.Data.SqlClient 
Using NuGet project 'EFCustomerModel'. 
Using StartUp project 'PMEL.DatabaseSetup'. 
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. 
    at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) 
    at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) 
    at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) 
    at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) 
    at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) 
    at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) 
    at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) 
    at System.Data.Entity.Internal.LazyInternalConnection.Initialize() 
    at System.Data.Entity.Internal.LazyInternalConnection.get_Connection() 
    at System.Data.Entity.Internal.LazyInternalContext.get_Connection() 
    at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo) 
    at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 
Format of the initialization string does not conform to specification starting at index 0. 

तो, यह माइग्रेशन में या वहाँ एक असमर्थित परिदृश्य है मेरे पास जाने का एक और तरीका है कुंजी या शायद मेरे कनेक्शन तार उत्पन्न करने का एक और तरीका है?

धन्यवाद,

+0

तो, मैं किसी भी आशा खोना हूँ! ;-) – jjslagace

+0

क्या आप समाधान ढूंढने में कामयाब रहे? – Alireza

उत्तर

3

आप -ConnectionStringName पैरामीटर के साथ अपने कस्टम कनेक्शन कारखाने के लिए एक महत्वपूर्ण पारित करने के लिए सक्षम होना चाहिए। यह पैरामीटर CreateConnection विधि को पारित किया जाएगा।

एक अन्य संभावित समाधान अपने कोड से डीबी प्रवास कॉल करने के लिए होगा:

var configuration = new Configuration(); 
configuration.TargetDatabase = new DbConnectionInfo(
    "Server=MyServer;Database=MyDatabase;Trusted_Connection=True;", 
    "System.Data.SqlClient"); 

var migrator = new DbMigrator(configuration); 
migrator.Update(); 
+0

धन्यवाद, मैंने पहले से ही -ConnectionStringName पैरामीटर के साथ प्रयास किया है, लेकिन शायद मुझे इसे फिर से संस्करण 5 के साथ आजमाएं। – jjslagace

+0

नहीं, यह काम नहीं करता है और डीबीमिगरेटर कन्स्ट्रक्टर विफल रहता है, डिफ़ॉल्ट कन्स्ट्रक्टर और आईडीबीकॉन्टेक्स्टफैक्टरी <> की कमी के बारे में शिकायत करता है। – Alireza