Hallo zusammen,
ich habe ein kleines Problem mit der Verwendung der DbProviderFactory.
Ich habe ein Projekt bestehend aus mehreren DLLs (BC, BE, DAL usw...) und eine WinForm - Anwendung.
Mit folgendem Code will ich auf eine App.config (der WinFormAnwendung) zugreifen:
Auszug der app.config:
Ich bekomme die Meldung "Instance failure.".
Der ConnectionString der "_connection" ist gesetzt und funktioniert in anderen Anwendungen auch.
Timout steht auf 15, State ist "closed".
Im INet habe ich auch nicht wirklich was gefunden.
Hat da jemand eine Idee?
Vielen Dank.
ich habe ein kleines Problem mit der Verwendung der DbProviderFactory.
Ich habe ein Projekt bestehend aus mehreren DLLs (BC, BE, DAL usw...) und eine WinForm - Anwendung.
Mit folgendem Code will ich auf eine App.config (der WinFormAnwendung) zugreifen:
Code:
private ConnectionInformation _connectionInformation;
private IDbConnection _connection;
/// <summary>
/// represents the connection settings
/// </summary>
private class ConnectionInformation
{
private DbProviderFactory _providerFactory;
private ConnectionStringSettings _settings;
public ConnectionInformation(ConnectionStringSettings settings)
{
this._providerFactory = DbProviderFactories.GetFactory(settings.ProviderName);
this._settings = settings;
}
/// <summary>
/// creates connection, specified by config file
/// </summary>
/// <returns>IDbConnection</returns>
public IDbConnection createConnection()
{
IDbConnection connection = _providerFactory.CreateConnection();
connection.ConnectionString = _settings.ConnectionString;
return connection;
}
}
#endregion
// DBConnectionClass
private ConnectionInformation _connectionInformation;
private IDbConnection _connection;
public DBConnection()
{
initConnectionInformation();
openConnection();
}
private void openConnection()
{
_connection = _connectionInformation.createConnection();
_connection.Open(); // <--- hier kommt die u.g. Meldung
}
private void initConnectionInformation()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringSettings setting = config.ConnectionStrings.ConnectionStrings["db"];
_connectionInformation = new ConnectionInformation(setting);
}
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key ="DatabaseConnection" value ="SqlServer"/>
</appSettings>
<connectionStrings>
<add name ="db" connectionString="Data Source=Server\\SQLSvr;Initial Catalog=TestDB;Integrated Security=True;Pooling=False"
providerName ="System.Data.SqlClient"
/>
Ich bekomme die Meldung "Instance failure.".
Der ConnectionString der "_connection" ist gesetzt und funktioniert in anderen Anwendungen auch.
Timout steht auf 15, State ist "closed".
Im INet habe ich auch nicht wirklich was gefunden.
Hat da jemand eine Idee?
Vielen Dank.