0

I'm getting a

'ConnectionString' threw an exception of type 'System.Configuration.ConfigurationErrorsException'

each time I try to run my WinForm.
Any idea how to solve It?

Exception received

This is my C# code:

public class DB
{
    /// <summary>
    /// 
    /// </summary>
    public static string ConnectionString
    {
        get
        {
            string connStr = ConfigurationManager.ConnectionStrings["Stoica Mihai"].ConnectionString;

            OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder(connStr);
            //sb.ApplicationName = ApplicationName ?? sb.ApplicationName;
            //sb.ConnectTimeout = (ConnectionTimeout > 0) ? ConnectionTimeout : sb.ConnectTimeout;

            return sb.ToString();
        }
    }
    /// <summary>
    /// Returns an opened connection to the database
    /// </summary>
    /// <returns></returns>
    public static OracleConnection GetSqlConnection()
    {
        OracleConnection conn = new OracleConnection(ConnectionString);
        conn.Open();
        return conn;

    }
    /// <summary>
    /// Override the connection timeout
    /// </summary>
    public static int ConnectionTimeout { get; set; }
    /// <summary>
    /// Used to override the name of the application
    /// </summary>
    public static string ApplicationName { get; set; }
}

1 Answer 1

0

It seems that System.Configuration doesn't know how to get the connection when the connectionString attribute is added in the app.conf file.

In this case in the app file, after the Oracle.ManagedDataAccess reference has been added, it need to configure first the dataSources that are created automatically with the configuration setting of the database: " Connection String Print Screen "

After these changes the connection worked

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .