Separate config file for Providers - config

In a small test project, I currently have the provider sections in the web.config. I want to move that to a separate config file, like providers.config. My current provider instantiation code is like:
//Get the feature's configuration info
ProviderConfiguration pc = (ProviderConfiguration)ConfigurationManager.GetSection(DATA_PROVIDER_NAME);
This code works if the provider info is in web.config, but how to I read this info from another file (like providers.condfig) because it seems that the ConfigurationManager "reads" only web.config file. I may be missing something very simple here :)
Would love to get more inputs on this.
Thanks
V

If you want to reference an external file for a collection of settings in the web.config you can do this:
<?xml version="1.0"?>
<configuration>
<appSettings file="externalSettings.config"/>
<connectionStrings/>
<system.web>
<compilation debug="false" strict="false" explicit="true" />
</system.web>
Hope this helps.
So in your case you can do something like this:
<configSections>
<section name="ProviderName" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<ProviderName file="provider.config" />

Related

Sql connection string for another pc

I have an application that runs on SQL 2005 database
I m trying to use same application on another machine same network,
I managed to log in on SQL 2005 using IP
Now I need to configure applications app.config file (found in visual studio solution) to allow connection
soo far I tried this connection string which isn't worked
this is what my config file looks like
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=ipaddress,1433;Initial Catalog=sample;User ID=sample;Password=sample;Trusted_Connection=True;" />
</appSettings>
</configuration>
Any help would be appreciated
Add this to your config file. Rather then using an appSetting use the actual connectionStrings section.
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=00.000.0.00,1433;Initial Catalog=taxi;Persist Security Info=True;User ID=sample;Password=sample; providerName="System.Data.SqlClient" />
</connectionStrings>
This string should work if anyone else got the same problem
thanks everyone for looking and trying to figure it out with me
<add key="ConnectionString" value="Data Source=00.00.000.000;Initial Catalog=sample;User ID=sample;Password=sample;" />

appsetting not working in wcfservice web.config file

Detailed Error Information:
Module IIS Web Core
Config Error The configuration section appSetting cannot be read because it is missing a section declaration
my web.config file below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSetting>
<add key="myserver" value="localhost:12345,localhost:12346"/>
</appSetting>
</configuration>
Try using appSettings instead.

what trustlevel must I use?

I am launching my first website. I have published it and I am getting this error.
The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
What trustlevel should I use now the site is online?
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
</system.web>
are there any other web.config settings I must be aware of now I am putting the site online? Like changing the connectionstring?
Fixed it by using
<trust level="Full" />
inside <system.web>
Depending on your host provider, you may need to take out the compilers as well.
In my experience with GoDaddy I had to comment out my compilers and put trust level="Full".
Set your custom errors to On or RemoteOnly so end users do not see any error messages a.k.a "the yellow screen of death".
<system.web>
<trust level="Full" />
<customErrors mode="On" />
..... other settings in system.web ...
</system.web>
<system.codedom>
<compilers>
<!-- <compiler language="..." /> -->
<!-- <compiler language="..." /> -->
</compilers>
</system.codedom>

Connection String in a VB.NET Application

I used to work only with asp.net websites before. I know that in ASP.NET website, the connection string is found in the web.config file.
My problem is now I have started working with VB.NET applications which needed to be interfaced to a database. How is a connection string created and where should I put it?
Thanks!
Here's the whole app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="dbAsthmaConnectionString" connectionString="Data Source=9300-00\SQLEXPRESS;Initial Catalog=dbStore;Persist Security Info=True;User ID=johnsmith;Password=1234" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
Ok here is an axample :
1- Your app.config should look like this :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Amlakconn" connectionString ="Data Source=KHASHAYAR-PC\SQLEXPRESS;Initial Catalog=Amlak;Integrated Security=True"/>
</connectionStrings>
</configuration>
2- and in your code you can access the connectionsttring this way :
private string conn = ConfigurationManager.ConnectionStrings["Amlakconn"].ConnectionString;
go try It ;)
The other answers tell you where to put the connection string: http://msdn.microsoft.com/en-us/library/ms254494(v=vs.80).aspx
This is the easiest way to create a Connection String.
a) Create a Text file, rename the extension from TXT to UDL, press enter.
b) Double click the UDL file and choose OLEDB Provider For SQL Server > Next > type the Database Server name > Select the database and click Test Connection.
c) When the Test passes, close the UDL file and open it with notepad, the bold lines are the connection string:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YourDatabase;Data Source=SQLEXPRESS
If you are working on a webapp project It's the same ! you can put that in the web.config file , and if you project is win app you can add an app.config file to your project and pu the connection string in there !
Non ASP.NET application can also use config file, it is just not named web.config. This file has exactly the same structure you know from ASP.NET including ConnectionStrings section. You can copy content from web.config and paste sections you need into app.config. In project it will show as app.config but in the bin folder it is named after the executable file name (with exe extension) plus ".config".
To create this file, go to project's Add -> New Item and select Application Configuration File. To get access to your connection strings create/copy <ConnectionString> section into <configuration> section and then use this code:
string conStr = ConfigurationManager.ConnectionStrings["ConStringName"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter("Select * from Users", conStr);
You need to add reference to `System.Configuration' assembly.

Merge wcf app.config with another config file another project?

I have a MyProject.config file that contains ConnectionStrings, AppSettings, and custom sections. I don't want to have to duplicate these settings in the wcf app.config file. Is it possible to merge MyProject.config with app.config or web.config if it is hosted in IIS. If so, where in the code would I do this and how would it be done?
As an example, in MyProject.config, I have a section group called Common and in Common I have AppSettings and ConnectionStrings. I know I can duplicate this in app.config, but then I would have to maintain it in two places.
MyProject.config:
<?xml version="1.0"?>
<configuration>
<sectionGroup name="common">
<section name="appSettings" />
<section name="connectionStrings" />
</sectionGroup>
</configSections>
<common>
<appSettings>
<add key="UserName" value="test" />
<add key="Password" value="test" />
</appSettings>
<connectionstrings></connectionstrings>
</common>
app.config for wcf contains ServiceModel configuration, I dont' want to have to put the above in app.config. I want to read it, does this make sense?
WCF will only load the config based settings for a service from the .NET configuration file for an application (web.config for IIS hosted services). Essentially you are fighting the .NET configuration file model.
If you want to keep the files separate then decide what will act as your primary config file and then use the configSource model for combining multiple config files