Whi can't I read config file

G

Guest

I use the following app.dll.config file to store connection string. The string always returns null when I try to retrive it. Here is what I have for the app.config and base class code: I used a similar code in ASP.NET and it works fine. What is the problem ?

<?xml version="1.0" encoding="utf-8" ?><configuration><appSettings><add key="connectString" value="data source=mimora; user id=scott; password=tiger" /></appSettings></configuration>


using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Collections.Specialized;
using System.IO;


namespace Com.AAD.Business
{
/// <summary>
/// Summary description for Class1.
/// </summary>
abstract public class DataLayerBase : IDisposable
{
private OracleConnection _connection;

public DataLayerBase()
{
try
{
string connStr= System.Configuration.ConfigurationSettings.AppSettings["connectString"];
_connection = new OracleConnection(connStr);
}
catch (OracleException exep)
{
throw (exep);
}
catch (Exception exep)
{
throw (exep);
}
// _connection = new OracleConnection("data source=mimora; user id=scott; password=tiger");
}

protected OracleConnection Connection
{
get {
return _connection;
}
}
public void Dispose()
{
_connection.Dispose();
}

}
}
 
M

Miha Markic

Hi anon,

Config files are tied to executables and not to libraries.
You'll have to put your connection string into app.exe.config file.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

anon said:
I use the following app.dll.config file to store connection string. The
string always returns null when I try to retrive it. Here is what I have
for the app.config and base class code: I used a similar code in ASP.NET
and it works fine. What is the problem ?
<?xml version="1.0" encoding="utf-8" ?><configuration><appSettings><add
key="connectString" value="data source=mimora; user id=scott;
password=tiger" /> said:
using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Collections.Specialized;
using System.IO;


namespace Com.AAD.Business
{
/// <summary>
/// Summary description for Class1.
/// </summary>
abstract public class DataLayerBase : IDisposable
{
private OracleConnection _connection;

public DataLayerBase()
{
try
{
string connStr= System.Configuration.ConfigurationSettings.AppSettings["connectString"];
_connection = new OracleConnection(connStr);
}
catch (OracleException exep)
{
throw (exep);
}
catch (Exception exep)
{
throw (exep);
}
// _connection = new OracleConnection("data source=mimora; user id=scott; password=tiger");
}

protected OracleConnection Connection
{
get {
return _connection;
}
}
public void Dispose()
{
_connection.Dispose();
}

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top