Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Mon, 15 May 2006 07:31:02 -0700,    group: microsoft.public.dotnet.distributed_apps        back       


class library   
I'm creating a Class Library that will be used by multiple projects, I want 
to read a config file (app.config) for my database connection string(s), how 
can i get the class library to read the app.config file for my connection 
string?
date: Mon, 15 May 2006 07:31:02 -0700   author:   CSharpguy

Re: class library   
Hello CSharpguy,

Just using System.Xml namespace

C> I'm creating a Class Library that will be used by multiple projects,
C> I want to read a config file (app.config) for my database connection
C> string(s), how can i get the class library to read the app.config
C> file for my connection string?

---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not 
cease to be insipid." (c) Friedrich Nietzsche
date: Mon, 15 May 2006 19:03:36 +0000 (UTC)   author:   Michael Nemtsev

Re: class library   
I did, and the connection string is coming back blank from my app.config file. 
its not reading the file for the database connection

"Michael Nemtsev" wrote:

> Hello CSharpguy,
> 
> Just using System.Xml namespace
> 
> C> I'm creating a Class Library that will be used by multiple projects,
> C> I want to read a config file (app.config) for my database connection
> C> string(s), how can i get the class library to read the app.config
> C> file for my connection string?
> 
> ---
> WBR,
> Michael  Nemtsev :: blog: http://spaces.msn.com/laflour
> 
> "At times one remains faithful to a cause only because its opponents do not 
> cease to be insipid." (c) Friedrich Nietzsche
> 
> 
>
date: Mon, 15 May 2006 14:19:01 -0700   author:   CSharpguy

Re: class library   
CSharpguy,
You read the app.config in a class library the exact same way you would in 
an application:

    using System.Configuration;

        // .Net 1.x
        String connectionString = 
ConfigurationSettings.AppSettings["MyExcelFileName"];

        // .Net 2.0
        String connectionString = 
ConfigurationManager.ConnectionStrings["MyExcelFileName"].ConnectionString;


    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="" value=""/>
      </appSettings>
      <connectionStrings>
        <add name="" connectionString="" providerName="" />
      </connectionStrings>
    </configuration>

In the .Net 2.0 case be certain to add a reference to the 
System.Configuration assembly.

As you may have noticed above .Net 2.0 includes a new connectionStrings 
section in the app.config for storing connection strings. I recommend using 
this new section as it leverages the new DbProviderFactory methods.


The trick to reading from the app.config is, that a class library doesn't 
have its own app.config, it uses the one from the application (the exe). So 
you need to be certain the app.config for the executable contains your 
settings!

-- 
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"CSharpguy"  wrote in message 
news:143C9A48-2239-4E2E-B465-BB1AD601C0D9@microsoft.com...
| I'm creating a Class Library that will be used by multiple projects, I 
want
| to read a config file (app.config) for my database connection string(s), 
how
| can i get the class library to read the app.config file for my connection
| string?
|
|
date: Tue, 16 May 2006 07:05:19 -0500   author:   Jay B. Harlow [MVP - Outlook]

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us