Skip to main content

All Questions

Filter by
Sorted by
Tagged with
445 votes
22 answers
859k views

Get connection string from App.config

var connection = ConnectionFactory.GetConnection( ConfigurationManager.ConnectionStrings["Test"] .ConnectionString, DataBaseProvider); And this is my App.config: <?xml version="1.0" ...
Moham ad Jafari's user avatar
130 votes
5 answers
130k views

How should I edit an Entity Framework connection string?

I recently had to edit my app.config file to change the connection string for an Entity Framework data model (.edmx file). But I'd like to know: Is there a way to edit the EF connection string using ...
DeveloperDan's user avatar
  • 4,674
26 votes
4 answers
30k views

Encrypting connectionStrings section - utility for app.config

Is there a utility that will encrypt a named configuration section (or just the connectionStrings section) in an app.config file in a similar manner that one can use aspnet_regiis with web.config ...
Oded's user avatar
  • 496k
23 votes
12 answers
20k views

Get user and password from ConnectionStringSettings

How can I get the user and password from such a connectionString in the app.config with a .NET function? Of course I could read that string and get the value after the ID= and Password=. <...
msfanboy's user avatar
  • 5,293
21 votes
4 answers
5k views

.Net Encryption

What I would like to know is the definite approach to encrypting connection strings in a config file. Here are my questions: Using machine-level encryption, can't anybody accessing my server write a ...
Gus's user avatar
  • 10.7k
19 votes
3 answers
50k views

App.config connection string relative path

I need to set in the app.config the sqlite connection string. I want to set the path relative to the debug/release folders the database file will be copied to those folders. <add name="...
Radu D's user avatar
  • 3,555
19 votes
3 answers
12k views

Centralize connection strings for multiple projects within the same solution

I currently have three projects in my solution that all have their own App.config file with the same exact connection string. Is there a way to consolidate the connections strings / app.config files ...
Mithrilhall's user avatar
  • 1,502
15 votes
6 answers
55k views

Multiple SQL Server connection strings in app.config file

I'm interested in displaying in a Windows Forms app a list of N radio buttons for the user to choose a target database server. I would like to add the SQL Server connection strings in the app.config ...
Benjamin Ortuzar's user avatar
13 votes
4 answers
20k views

Reading connection string from external config file

I have created a console application and an app.config file and Connections.config file. The app.config file has a connectionstring property source pointing to the Connections.config When I tried to ...
PSR's user avatar
  • 893
11 votes
4 answers
14k views

ConnectionStrings in app.config with characters that the .config file doesn't like

I've looked for the answer and can't find it. It's got to be something obvious and I'm just missing it. We have a connection string issue in an app.config file. It uses SQL Server authentication, ...
David's user avatar
  • 73.3k
9 votes
1 answer
7k views

Is ConfigurationManage -> section.SectionInformation.ProtectSection() machine dependent?

in the code Configuration config = ConfigurationManager.OpenExeConfiguration (Application.ExecutablePath); ConnectionStringsSection section = config.GetSection("connectionStrings") as ...
Fabio's user avatar
  • 1,046
9 votes
4 answers
4k views

c# - Entity Framework ConnectionString won't update after changing App.Config in runtime

I'm developing a WPF application which depends on Entity Framework for data access. At the first time installation I need to create a new connection string based on the User input, then updating App....
evolon's user avatar
  • 1,516
9 votes
2 answers
2k views

Database file not copied during publishing so installed application throws exception

I am developing a C# windows form application containing a service based data based. when I test my application it's database works fine but after publishing and installing the program when program ...
Behnam's user avatar
  • 1,045
8 votes
2 answers
2k views

app.config and 64-bit machines

I have an app that works fine on 32-bit systems, but fails on XP 64 bit systems. I've tracked it down to the connection string defined in my app.config thus: <connectionStrings> <...
Dale Lutes's user avatar
7 votes
4 answers
2k views

How to configure database connection securely

Similar but not the same: How to securely store database connection details Securely connecting to database within a application Hi all, I have a C# WinForms application connecting to a database ...
chiccodoro's user avatar
  • 14.6k
6 votes
2 answers
9k views

Is it possible (and how) to add ConnectionString to app.config at runtime in C#?

I have a console application which gets the connectionstring as a parameter. I would have to set a ConnectionString in app.config with name 'ConnectionString' and the given parameter as the sql ...
Lieven Cardoen's user avatar
6 votes
2 answers
2k views

How do I create a Solution Wide Connection String

Does anyone know if it is possible to create a single connection string that will be accessible to all the projects in a solution (we have about 6). I can create a text file with this information, ...
Renier's user avatar
  • 83
5 votes
4 answers
56k views

how to define a connection string using an app.config file in C# [duplicate]

Currently i manually define my connection string in my C# code: string ConnectionString = "Data Source=C;Initial Catalog=tickets;Integrated Security=True"; SqlConnection Conn = new SqlConnection(...
PriceCheaperton's user avatar
5 votes
4 answers
5k views

How to access a connection string from within a library

I have a web project (mvc) and data access layer in a separated class library project. I need to access to a connection string in app.config which sits in that library project. ConfigurationManager....
iLemming's user avatar
  • 35.6k
5 votes
1 answer
15k views

How to use Application Data in an (App.config) connectionString

I've got an SQL Server CE database in a project that I wan't to store somewhere in the %AppData% directory. However I can't find a way to make a reference to the Application Data path in the ...
Sander's user avatar
  • 616
5 votes
2 answers
2k views

Is there a way to use Slow Cheetah to transform app.config in Azure Worker Role?

I am trying to use Slow Cheetah to switch between a local db connection string and a SQL Azure connection string. This is in a Azure worker role that I am pushing to Azure with TeamCity. When I look ...
Jack Woodward's user avatar
4 votes
2 answers
3k views

Using Entity Framework app.config how to switch between environments Dev, Stage and Production

I have a windows application accessing Dev database using DataModel.edmx and it works fine. To access stage environment database I have added another StageDataModel.edmx. So there are two connection ...
Poonam E's user avatar
  • 159
4 votes
2 answers
16k views

Connection String for SQL Server 2008 (version 10.0.1600) in Application Configuration File

I am new to create connection string and application configuration file. I use an example which showed connection to SQL Server CE using file which is what I do not want instead I want to connect to ...
Fakhar Anwar's user avatar
4 votes
1 answer
6k views

Iterate through connections strings in App.Config file in VB.Net

I am trying to iterate through all the connection strings in App.Config using VB.net. I would like to: 1. Get a count of all the connection strings 2. Put them all into a listbox. I have tried using ...
Jeremy's user avatar
  • 3,950
4 votes
3 answers
3k views

PowerShell update connection strings

I have the following script that will update the connection string across three different config files used in development. function Main() { pushd cd .. $aomsDir = pwd $configFiles = @( 'util\...
user avatar
4 votes
3 answers
2k views

Why is App.config a more secure location for storing a connection string than in the source code?

Simple question, I know that storing a connection string in plain text in your source code is a bad idea, as somebody can use a tool like Ildasm.exe to decompile and subsequently view your connection ...
JMK's user avatar
  • 27.9k
4 votes
0 answers
4k views

How to use encrypted connection string on app.config with Dataset.xsd generated by Wizard on Windows Form

I'm developing an MDI application with Visual Studio 2013 (.NET 4.5) and Oracle Developer Tools latest release. I need to create a main form that then will be the container for many different forms, ...
Cheshire Cat's user avatar
  • 1,961
3 votes
1 answer
3k views

How to refer from NLog to my connection string in app.config

I have a .net core 3.1 Console project. I'm trying to set it up to use NLog. I use 2 targets, db and file. I can write to the file but can't to the db. I'm sure the connection string is correct ...
user1019042's user avatar
  • 2,168
3 votes
2 answers
2k views

c# connection string and concatenation app.config

I have the following connection string through which i connect to an Access database(.mdb) located in a sub-folder inside the root-folder of my application : OleDbConnection con = new ...
Aousaf Rashid's user avatar
3 votes
1 answer
523 views

.NET 2.0 App.Config connection strings includes unwanted SQLExpress default

I'm using a connectionStrings section within an app.config file in a .NET 2.0 project. The config section contains two connection strings I have defined. When I retrieve the ...
tomfumb's user avatar
  • 3,741
3 votes
1 answer
6k views

Encrypt connection string in NON ASP.Net applications

I am working with C# & WPF and, of course, an app.config file. I have not been able to find an example of encrypted connection strings, stored in the app.config. There's plenty of examples for ASP....
Unknown Coder's user avatar
3 votes
1 answer
2k views

Adding some basic layer of security to the app.config file in WPF

Lately I've been a bit concerned with the security of my WPF app. I'm just starting out so security hasn't been my main focus but now I'm a bit worried that someone might open the .exe.config file in ...
Cosmin's user avatar
  • 585
3 votes
2 answers
2k views

C# ConfigurationManager retrieves wrong connection string from app.config

I have a simple WinForms app that will eventually be a game. Right now, I'm just working on the data access layer of it and I've run into a snag. I created a separate project called DataAccess and ...
Kyle Rone's user avatar
  • 305
3 votes
1 answer
20k views

Winforms connection strings from App.config

I have a Winforms app that I am developing in C# that will serve as a frontend for a SQL Server 2005 database. I rolled the executable out to a test machine and ran it. It worked perfectly fine on the ...
Geo Ego's user avatar
  • 1,325
3 votes
1 answer
434 views

Unable to read newly added connection string from app.config file

I am adding a connection string at runtime to my App.config file as shown below: ConnectionStringSettings connSettings = new ConnectionStringSettings("dbConnectionString", "Data Source=DBSERVERNAME,...
subs's user avatar
  • 2,209
3 votes
1 answer
4k views

Configuration manager does not find connection string from app.config file

I added System.Configuration.dll as a reference. When I try to get a connection string by name, I get a null reference exception. So I tried to see if it has any using the following code: for (int i =...
Error's user avatar
  • 825
3 votes
3 answers
10k views

Change connection string from class library in main application at run-time

You can change the connection string at run-time like this. You make the connection string setting available for writing as a separate property inside the MySettings class: Partial Friend ...
Dragoljub Ćurčić's user avatar
2 votes
3 answers
5k views

ConnectionStrings in app.config. What about security?

Is it really a Good Thing to put connection strings with passwords in the app.config file? It seems to me that the app.config is not encrypted in any way and the password information can be easily ...
paul's user avatar
  • 13.5k
2 votes
2 answers
2k views

Set app.config file connection string dynamically

I have a web application that comprises the following: An MVC web project (with a web.config file containing a connection string - but no database access code in it) A data access project (it is a ...
Sudha's user avatar
  • 2,098
2 votes
2 answers
2k views

Entity framework 4.1 modify connection string for each developers unit test environment

We have an Entity framework 4.1 setup, auto generated POCOs and DbContext classes for interaction with the db. The automatically generated DbContext derived class looks like this: public MyEntities(...
Coopernick's user avatar
2 votes
3 answers
334 views

Unable to connect to Local SQL database from app.config in windows form application

i am trying to connect my local MySQL database to my windows form application using app.config. but i am keep on getting the below mentioned Exception.Can anyone help me please. Exception : App....
ramki_ramakrishnan's user avatar
2 votes
1 answer
6k views

Make the connectionstring's AttachDbFilename relative in config file

I am working on a project using an mdf file generated locally using Entity Framework Code First. The path to this mdf is set in several config files in my solution using <connectionStrings> ...
Sbu's user avatar
  • 910
2 votes
6 answers
732 views

Where i put the Connectionstring with numerous client?

i will develop utility program for a company with more than 1000 client and the program must be win application with .Net because my program will act with another program. What is your suggest for ...
Meysam Javadi's user avatar
2 votes
2 answers
971 views

Inject connectionstring from app.config vs read it from a BaseDataProvider class

Do you see any benefit in injecting the database connnection string from the Global.asax.cs class in ASP.NET MVC compared to the method in reading the connection string from a BaseDataProvider class ...
Pascal's user avatar
  • 12.7k
2 votes
3 answers
12k views

How to read <connectionstring> of web.config from a console application?

I have VB.net console application. I would like to read the (ConnectionString) from a web.config. Web.config is located at a particular path in my virtual PC, say "C:/mywebConfig" <add name="...
JADE's user avatar
  • 523
2 votes
1 answer
633 views

C# Read Spring Framework Connection String

Many other questions here focus on the use of System.Configuration.ConfigurationManager... For my issue, I need to pull the connection string from a Spring object in order to determine the server ...
Joshua Morgan's user avatar
2 votes
1 answer
372 views

Correctly accessing the connection strings from Data Layer config file

I have a n-tiered wpf application using EF in Data Access Layer. The simplified structure looks like this - DataProject.csproj * data.config * Repository.cs - Presentation.csproj * ...
Marshal's user avatar
  • 6,611
2 votes
1 answer
1k views

How do i retrieve the ConnectionString from app.config file for entity framework without getting a null reference exception

I want to retrieve the ConnectionString from the app.config in the DataAccess class library for use in Entity Framework's .edmx model of the application by using this code using System; using System....
Cizaphil's user avatar
  • 520
2 votes
1 answer
2k views

How to refer to app.config for connection string when adding dataset using dataset wizard?

Whenever I add dataset in my class library project using the wizard it gives me an option to save the connection string in app.config file and after selecting the option it do save the string in file ...
Safran Ali's user avatar
  • 4,477
2 votes
1 answer
3k views

Dynamic Connection Strings for Strongly Typed DataSet in a Class Library using App.Config

This is my first question on StackOverflow.com and I'm not sure if this is the correct way to do this. I found a similar question titled: Modifying the Data Source for the Strongly Typed Dataset ...
Luc's user avatar
  • 1,850