I have a class library where I store a connection string in the application settings:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="FAB.IMon.DataAccess.Properties.Settings.IMonConnectionString"
connectionString="X" />
</connectionStrings>
</configuration>
I implemented a WCF Soap service wich references this library. In my WCF service I want to use connection string Y. So I changed the web.config:
<connectionStrings>
<add name="FAB.IMon.DataAccess.Properties.Settings.IMonConnectionString"
connectionString="Y" />
</connectionStrings>
When I start the Webservice the service uses X instead of Y, why?
Related
I normally work with ASP.NET MVC web projects so the connection string always goes into the web.config file.
Where do I put it in my WPF project?
Put it in your app.config under the configSections tag
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
...
</configSections>
<connectionStrings>
<add name="MyModel" connectionString="MyConnectionString" />
</connectionStrings>
...
If you don't have an app.config file you can create one manually.
You'll probably have to create an App.config file in your project by hand. Then you can fill it up as usual.
I work with asp.net fromwork 4.0 web site. and I want to encrypt web.config file connectionString. I used aspnet_regiis -pef "connectionString" "file Location"
but it's not working. Rather I'm getting only the error message as shown below
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<connectionStrings>
<add name="MS_EAS_LocationConnectionString" connectionString="Data Source=help\sqlexpress;Initial Catalog=MS.EAS.LOCATION;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
I have a console application and in the App.config I need to add a connectionString to another SQL server that is in the same network.
If I try the connectionString to a local server by only passing the Server='localhost' its worked but I cannot make it work for an outside server.
Thanks
Here is the connection file
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<connectionStrings>
<add connectionString="Server=LocalServer;database=DAtaBase;user=UserName;pwd=Password" name="Connection"/>
</connectionStrings>
</configuration>
Example connection to outer server:
<connectionStrings>
<add name="Namespace.Settings.outerSQL" connectionString="Data Source=192.168.0.100\SQLEXPRESS;Initial Catalog=database_name;User ID=user;Password=password"/>
</connectionStrings>
You need address to remote server and credentials provided (if it's not Windows auth, for which you use "Integrated Security").
inside of a app.config / web.Config file you would have the following and this is a simple and easy way to connect to a sql server database.. also confirm what database you are using because the connection string can be different depending on the DBMS
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DbConn" connectionString="Data Source=the name of your database;User Id=UserName;Password=Password;"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
I am trying to use ConfigurationManager to get the connection string from a project call FileShareAccessLibrary.
This is the code I am writting in order to do this:
ConfigurationManager.ConnectionStrings["FileShareAccessLibrary"].ConnectionString
This is the content of app.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="FileShareAccessLibrary" connectionString="......"
providerName="System.Data.SqlClient" />
<add name="FileShareAccessLibrary.Properties.Settings"
connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
When I run my app I get a NullReferenceException because ConfigurationManager.ConnectionStrings["FileShareAccessLibrary"] returns null.
While debugging I noticed that none of the two connection strings are stored inside ConfigurationManager.ConnectionStrings so I figured that the ConfigurationManager is pointing to another file.
In my project I have not other app.config file.
Is there something I am doing wrong here?
Why is ConfigurationManager not getting my connection string?
If your FileShareAccessLibrary project is a class library rather than a windows forms application or console application then you will need to move the connection strings (and app settings if you have any) from the FileShareAccessLibrary config file to the config file of the application(s) that reference the FileShareAccessLibrary dll.
I had developed C# application. and used external tool for themes.
Before creating setup for this application it works fine. and no problem in database connection.
But after creating setup for this application and installing it, connection to database not created.
I have used app.config file for getting connection string. Am I missing something when creating setup or the problem due to external theme?
My app.config code
<?xml version="1.0" encoding="utf-8" ?>
<configuration> <connectionStrings>
<add name="connectionStrings" connectionString="Data Source=SUMEET-PC\SQLSERVERNEW; Initial Catalog=ClothShop;User Id=sa;Password=123;" />
</connectionStrings>
</configuration>