c# – Failing at Database db = DatabaseFactory.CreateDatabase();

c# – Failing at Database db = DatabaseFactory.CreateDatabase();

Have you edited your .config sections? You need somethig like:

<section name=dataConfiguration type=Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 />

And you also need a config section pointing to the connection string you have defined in your connection strings section:

<dataConfiguration defaultDatabase=Connection String />

You might know why had you not ignored the exception. catch { ... } is rarely a good idea (its effectively never a good idea but I try to avoid always/never when giving recommendations).

Modify your code to something like this and see if you still need help:

try
{
    Database db = DatabaseFactory.CreateDatabase();

    ...
}
catch(Exception ex)
{
    // this will dump to the output window in VS when running a Debug build.
    // Release logging will require something different
    System.Diagnostics.Debug.WriteLine(ex);

    ...
}

c# – Failing at Database db = DatabaseFactory.CreateDatabase();

Leave a Reply

Your email address will not be published.