All Questions
Tagged with connection-string c#
1,776
questions
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" ...
395
votes
10
answers
423k
views
Entity Framework Timeouts
I am getting timeouts using the Entity Framework (EF) when using a function import that takes over 30 seconds to complete. I tried the following and have not been able to resolve this issue:
I added ...
273
votes
13
answers
462k
views
Read connection string from web.config
How can I read a connection string from a web.config file into a public class contained within a class library?
I've tried:
WebConfigurationManager
ConfigurationManager
But these classes are not ...
180
votes
16
answers
412k
views
How to read connection string in .NET Core?
I want to read just a connection string from a configuration file and for this add a file with the name "appsettings.json" to my project and add this content on it:
{
"ConnectionStrings": {
"...
126
votes
10
answers
1.1m
views
How can I set an SQL Server connection string?
I'm developing a simple C# application, and I'd like to know this: When I connect my application to SQL Server on my PC, I know the connection string (server name, password, etc.), but when I connect ...
114
votes
14
answers
434k
views
Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App
I have the following class in NET Core2.0 App.
// required when local database does not exist or was deleted
public class ToDoContextFactory : IDesignTimeDbContextFactory<AppContext>
{
...
93
votes
4
answers
119k
views
How to check if connection string is valid?
I'm writing an application where a user provides a connection string manually and I'm wondering if there is any way that I could validate the connection string - I mean check if it's correct and if ...
89
votes
13
answers
153k
views
Entity Framework change connection at runtime
I have a web API project which references my model and DAL assemblies. The user is presented with a login screen, where he can select different databases.
I build the connection string as follows:
...
73
votes
2
answers
117k
views
Persist Security Info Property=true and Persist Security Info Property=false
For the properties:
Persist Security Info=true
and
Persist Security Info=false
Can you tell me what is the difference between them, and if I don't put it in my connection what will happen?
...
70
votes
8
answers
209k
views
What is the connection string for localdb for version 11
I'm trying to do the Code First Walkthrough of the entity framework ( http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-code-first-walkthrough.aspx ).
I have the latest SQL Server Express and ...
65
votes
18
answers
471k
views
How to fix "The ConnectionString property has not been initialized"
When I start my application I get: The ConnectionString property has not been initialized.
Web.config:
<connectionStrings>
<add name="MyDB"
connectionString="Data ...
61
votes
2
answers
46k
views
connectionStrings configSource in App.config not working
I'm trying to separate my connection string from my App.config, and as you can't do transformations like with Web.config, I thought may I could use the configSource attribute to point to another ...
58
votes
20
answers
275k
views
System.Data.SqlClient.SqlException: Login failed for user
Working with my project in debug I have no issues. However running it in IIS I am getting this error:
System.Data.SqlClient.SqlException: Login failed for user 'domain\name-PC$'.
Stack Trace
[...
50
votes
7
answers
72k
views
SQL Express connection string: mdf file location relative to application location
I am using SQL Express databases as part of a unit test project in c#. My databases is located here:
./Databases/MyUnitTestDB.mdf
I would like to use a relative path or variable in the app.config ...
45
votes
2
answers
46k
views
How do I use Web.Config transform on my connection strings?
In my current project, I have some connection strings that are valid for local development machines:
<configuration>
<connectionStrings>
<add name="ApplicationServices"
...
39
votes
4
answers
64k
views
How to get connection string out of Azure KeyVault?
A hypothetical web-site currently connects using:
public SqlConnection CreateConnection()
{
DbConnection connection = new SqlConnection();
connection.ConnectionString = GetConnectionString();
...
36
votes
4
answers
101k
views
What is IMEX within OLEDB connection strings?
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=localhost;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"
What is the purpose of IMEX=2 in the above connection string?
34
votes
8
answers
30k
views
Get SqlConnection from DbConnection
I have an Extension method on DbContext where I want to do a SqlBulkCopy. Therefore I need a SqlConnection. The connection from the DbContext is from the type DbConnection though.
Among a few other ...
33
votes
4
answers
29k
views
Setting the SQL connection string for ASP.NET Core web app in Azure
I have created a new ASP.NET Core web application in Visual Studio 2015. I've also set up an Azure web app to pull in the app from GitHub and run it. This works fine, but I'm having trouble connecting ...
32
votes
3
answers
11k
views
Can I stop the dbml designer from adding a connection string to the dbml file? [duplicate]
We have a custom function AppSettings.GetConnectionString() which is always called to determine the connection string that should be used. How this function works is unimportant to the discussion. ...
30
votes
15
answers
61k
views
azure blob storage "No valid combination of account information found"
I have an MVC4 project that I am running using Azure websites preview.
My problem is that I cant upload a blob into my blob storage container when I have deployed my website to azure, however the ...
30
votes
4
answers
19k
views
AzureWebJobsDashboard Configuration Error
I created a new Azure WebJob project in Visual Studio 2015 using .NET Framework 4.6.
In the app.config, I set three connection strings:
AzureWebJobsDashboard
AzureWebJobsStorage
...
30
votes
5
answers
105k
views
Get Connection String from Web.config in asp.net
I want to know the ways to get connection string from web.config file in asp.net.
I just only know the below way .
using System;
using System.Collections.Generic;
using System.Linq;
using System....
29
votes
6
answers
20k
views
How i can use the connectionString of the current website for log4Net instead of configuring [duplicate]
I use log4Net for my system's log. The connectionString node is mandatory if the appender type is the AdoNetAppender in Log4Net. However, I already have a connectionString in my website where I use ...
26
votes
4
answers
37k
views
Testing - Connection string is missing
Visual studio created a unit test project for me based on a method (right-click add test). When I try to access the database, I get an exception. Ran this code to see what my connection was:
...
25
votes
8
answers
19k
views
Can I Add ConnectionStrings to the ConnectionStringCollection at Runtime?
Is there a way where I can add a connection string to the ConnectionStringCollection returned by the ConfigurationManager at runtime in an Asp.Net application?
I have tried the following but am told ...
24
votes
1
answer
49k
views
Right way to get username and password from connection string? [duplicate]
I have a connection string like this:
"SERVER=localhost;DATABASE=tree;UID=root;PASSWORD=branch;Min Pool Size = 0;Max Pool Size=200"
How do I get the various database parameters out of it? I can get ...
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=.
<...
23
votes
4
answers
8k
views
web.config transform - delete comments from connectionstring section
I store several different connection strings in my web.config for development and testing. All but one is commented out so I can change info as needed.
When I publish, I would like to replace ...
22
votes
1
answer
39k
views
Get the Server Name from Connection string Defined in App.config File? [duplicate]
I want to get IP Adress of ConnectionString's serverName from my app.config file and then ping it.
Actually i want ping my server before running my application.
how do i do this?
my ConnectionString
...
22
votes
8
answers
28k
views
Display a ConnectionString dialog
I'm trying to create a program in C# that should be able to create, backup and restore a SQL Server database.
For this, the user needs to be able to setup a connection string to the desired SQL ...
22
votes
9
answers
75k
views
How to change connection string in DataSet.xsd?
I have build my project in C#, I add DataSet.xsd, and connect him to
Oracle DataBase in my computer - work Excellent !!!!
When I installed on the customer computer (that connect to his Oracle ...
21
votes
1
answer
35k
views
The entry has already been added
All my Razors views have this error:
The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message:
The ...
21
votes
2
answers
7k
views
Encrypt and deploy app.config
I read and tested a lot to find the best practice to encrypt and deploy an app.config to different machines. In general, I would like to secure the content of the connection string from third parties ...
20
votes
1
answer
30k
views
Help with a OleDB connection string for excel files
The problem i'm having is that the data adapter is looking at only the first row in each column to determine the data type. In my case the first column "SKU" is numbers for the first 500 rows then I ...
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 ...
19
votes
2
answers
18k
views
Encrypting the connection string in web.config file in C#
I have written the name of my database, username and password in my web.config file as connection string.
I want to encrypt this data. How can I do it?
<connectionStrings>
<add name="...
19
votes
4
answers
57k
views
Entity Framework connection string not from config
public class Context : DbContext
{
public Context(string connString) : base(connString)
{
Database.SetInitializer(new MyContextInitializer());
}
//...
Need to pass a connection ...
18
votes
5
answers
41k
views
encrypt SQL connectionstring c#
I created an c# application (not asp webpage) which connects to a sql 2005 server. In my sourcecode the password and userid for this sql-server is coded plain text in ConnectionString.
SqlConnection ...
17
votes
4
answers
14k
views
Get Connection String in Azure Function v3
I am very confused. I want to get a connection string in an Azure v3 function (.Net Core 3.1).
My local settings looks like
{
"IsEncrypted": false,
"Values": {
&...
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 ...
14
votes
9
answers
22k
views
Managing A Debug and Release Connection String
What is a good approach to managing a debug and release connection string in a .NET / SQLServer application?
I have two SQL Servers, a production and a build/debug and I need a method of switching ...
14
votes
3
answers
25k
views
connection timeout property in connection string ignored
I'm building an app in C#. I'm using a connection string like:
DSN=SomeDataSource; Trusted Connection=yes; Uid=SomeId; pwd=somePwd; Connection Timeout=x
But no matter what value I set as x (...
14
votes
4
answers
19k
views
Specifying Port With SqlConnectionStringBuilder?
I've ran into a snag. I have a need to specify the port number for my local installation of SQL Server 2008 R2. So far I've tried using the SqlConnectionStringBuilder with the data source set as .\...
13
votes
2
answers
2k
views
Where does this permanent SQLExpress connectionstring come from (not web.config)?
Today I noticed that in my ConfigurationManager.ConnectionStrings the very first instance is .\SQLEXPRESS. I remembered explicitly removing this entry from my web.config so I checked again, but didn't ...
13
votes
2
answers
13k
views
Can't access the configuration manager from my solution
I have a three tier set-up. Someone suggested I should get the ConnectionString from the Web.Config file and I've got it set up like this:
Now I'm trying to access the ConnectionString from my DAL ...
13
votes
7
answers
34k
views
How to connect to mysql from C# over SSH
How can I connect to a mysql database trough C#,
This is my connection string now:
connectionString="server=localhost;port=3306;user id=root;Password=*****;database=Data" providerName="MySql.Data....
13
votes
4
answers
10k
views
winforms connection properties dialog for configuration string
Is there a way to display the connection properties dialog for connection string browsing(for database) in run time?
As I want the user to be able to connect to various database using the GUI.
The ...
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 ...
12
votes
3
answers
15k
views
Get multiple connection strings from web.config
How to get all the connection strings's names from the web.config via code in C#?
I tried this:
System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager....