I am using EF Code First in VS 2012 Ultimate with Firebird Dot Net Provider
3.0.2.0. 
I need to change the connection string run time as to connect to different
machine as required. 
In order to do that, I store the connection string in settings and create
the DBProviderFactory in code and pass the connection string to it. It is
working fine in my dev machine.
Here is the code that is use to create my connection,

private static DbConnection CreateDbConnection(string providerName, string
connectionString)
        {
            // Assume failure.
            DbConnection connection = null;

            // Create the DbProviderFactory and DbConnection.
            if (connectionString != null)
            {
                try
                {
                    var factory =
DbProviderFactories.GetFactory(providerName);
                    connection = factory.CreateConnection();
                    if (connection != null) connection.ConnectionString =
connectionString;
                }
                catch (Exception ex)
                {
                    // Set the connection to null if it was not created.
                    connection = null;
                    MessageBox.Show(EmailException.FormatException(ex));
                }
            }
            // Return the connection.
            return connection;
        }

But in my customer machine (Firebird Dot Net Provider 3.0.2.0. installed) it
throws "Unable to Find .Net Framework Data Provider". Here is the stack

An Unhandled Exception has occured in PearlPOS
----------------------------------------------
System.ArgumentException: Unable to find the requested .Net Framework Data
Provider.  It may not be installed.
   at System.Data.Common.DbProviderFactories.GetFactory(String
providerInvariantName)
   at
System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProvi
derName(String providerInvariantName)
   at
System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionS
tringSetting(ConnectionStringSettings appConfigConnection)
   at
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfi
g(String name, AppConfig config)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
   at System.Data.Entity.Internal.LazyInternalContext.get_Connection()
   at Pearlpos.Data.Utils.Database.get_DataSource()
   at My.MyApplication.ConnectDatabase()
   at My.MyApplication.Application_Startup(Object sender, StartupEventArgs
e)
   at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnStar
tup(StartupEventArgs eventArgs)
   at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoAppl
icationModel()
   at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(St
ring[] commandLine)
   at My.MyApplication.Main(String[] Args)
----------------------------------------------

Thanks,
Muthu Annamalai

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to