.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to use Connection Strings from IIS in my c# application

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net

Hello all,

Thanks in advace for your help.

I have a C# web service where I need to access a MS SQL DB. I see a way of creating a connection string in IIS and using it in the web application when connecting to the DB. In IIS in Connection strings you specify the name of the connection, server, user n pwd

How can I use the name of connection string created in IIS in my c# app.?

I am currently using

CustomerInfo customerinfo = new CustomerInfo<

View Complete Post

More Related Resource Links

Service Station: The Application Connection Designer


In some of my past columns on service orientation and contract-first development, I've mentioned the new suite of designers, formerly codenamed "Whitehorse," that are part of Visual Studio® Team edition for Software Architects Team System.

Aaron Skonnard

MSDN Magazine August 2005

Protect It: Safeguard Database Connection Strings and Other Sensitive Settings in Your Code


Protecting application secrets, such as database connection strings and passwords, requires careful consideration of a number of pertinent factors such as how sensitive the data is, who could gain access to it, how to balance security, performance, and maintainability, and so forth. This article explains the fundamentals of data protection and compares a variety of techniques that can be used to protect application settings. The author discusses what to avoid, such as hiding keys in source code and the use of Local Security Authority. In addition, he presents some effective solutions such as the Data Protection API.

Alek Davis

MSDN Magazine November 2003

Connection to Exchange Server of .NET 1.1 Framework application on Windows 2008 64-bit

I am running Visual Studio 2003 .NET Framework 1.1 application on Windows 2008 64-bit machine. There is only one problem - connection to Exchange Server. The same application is running fine on Windows 7 64-bit machine (not server). I tried to use the same Interop.MAPI.dll I used for Windows 7, but it doesn't work for Windows 2008.   Please help.  

SQLCE 3.5 connection from multiple application, data refresh

I have a native application (wm 6.5) using oledb to connect to a database. *******************************************************************************   result=CoCreateInstance(CLSID_SQLSERVERCE_3_5,0,CLSCTX_INPROC_SERVER,IID_IDBInitialize, (void**)&database);   ... // set properties  database->Initialize(); ******************************************************************************* This part of the app simply queries a single table for all records (query wrapped in a transaction of it own). I believe it is recommended that you keep a single connection for as long as possible, and therefore just create a new session each time I query the table. There is a second application (c#) which my application executes and then waits for. It updates and inserts new records. when the c# app closes and I get control back, my app then runs another query to see if anything has changed. My issue is that, the only way I can get the updated data is to un-initialize and re-initialize the database (IDBInitialize) interface created above.  Is there some properties I should be setting on the session/database in order for this to work. Or do I really have to spawn a new connection for every query?   Thanks in advance. Dylan

how to change the web application Database connection form Windows authentication to SQL Server acco

Hi, I have a web application created and Database connection authentication was given as Windows authentication. how can i change it to a SQL server account in MOSS 2007. Thanks in advance.

claims authenticated (FBA) user cannot open a connection to our custom application database

We have designed a custom sharepoint site. This site uses a membership provider that I implemented, and the users are stored in our custom application database. These are the steps I follow to reproduce the error: 1. Browse to our site. Select Forms Authentication from the default.aspx selection. 2. Enter in a username from our DB table. This user I have configured as a site collection administrator. 3. Login to the site. The user is authenticated by our membership provider and allowed access (ValidateUser returns true) 4. Browse to a page that attempts to connect to the custom app DB. 5. I get the following error when the page attempts to open a connection to our DB: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server NOTES: The code that opens the DB connection is running with SPSecurity.RunWithElevatedPrivileges. Our application pool account has access to the database. My user can connect to the database fine as well as the user that our  application pool is running as. I have validated the connection string that is being used in the debugger, and that is correct.

Encrypting connection strings and click-once publishing

Ok, so I've figured out the connection string encrypting.  I can encrypt it and it encrypts the .config file in the bin directory and not the one in the project solution, which makes sense.  Now, I go to publish it though with click-once and I end up getting two versions of the file in  ...\AppData\Local\Apps\2.0\... directory.  One is encrypted and the other is not.  This is unacceptable becuase it leaves the connection string in plain text on the user's computer.  Is there a way around this or some other method of instlling the program that it will also receive automatic updates and not have the unencrypted version floating around with plain text connection strings?

I need a dynamic connection string for my windows forms application.


Hello folks


I am brand new to forms applications and visual studio 2008 I am building a forms application to connect to a 3rd party's sdf file. There is no password or username required to connect however the 3rd party app installs the sdf in the users folder for me I am on windows 7 but I have clients on xp.


I went to add a data connection and chose sql ce file and browsed out to my location and it connects and works. But I need this connection string to be for whoever is logged into there laptops or computers no matter the operating system version xp,vista,7.


Data Source=C:\User\username\AppData\Roaming\PS\GES\surve.sdf


Can someone tell me how to do that. Also please explain in words a new borne could understand cause like I said I am new to this.


Thank you


Application deployment - database connection issue


Hi, I finished an intranet application using webconfig to store my connection string to an Access database which has linked tables to SQL Server 2005.

Everything works perfectly, but when I publish the application on a IIS server service, it seems like all connections fail... :(


I looked up on internet but found nothing on this. I think my webconfig file is correct :


    <add key="dbconnect" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=//192.168.xxx.x/Websites/xxx/xxx.accdb;Persist Security Info=True"/>


Any idea why it happens?


thanks alot !

n-tier, configuration info, specifically connection strings



I have an ASP.NET project which is pretty n-tier, by namespace, but I need to separate into three projects:  Data Layer, Middle Tier and Front End.

I am doing this because... 

A) It seems the right thing to do, and

B) I am having all sorts of problems running unit tests for ASP.NET hosted assemblies.

Anyway, my question is, where do you keep your config info?

Right now, for example, my middle tier classes (which uses Linq to SQL) automatically pull their connection string information from the web.config when instantiating a new data context.

If my data layer is in another project can/should it be using the web.config for configuration info?

If so, how will a unit test, (typically in a separate assembly) provide soch configuration info?

Thank you for your time!


Package configuration file with multiple connection strings


I am using the configuration file to read the connection string in the SSIS packages. In one of my packages i have to use two different connection strings. If i specify the second connection string in the config file, then the current package works well but other packages fails during validation saying the second connection manager does not exist in the package. Is it not possible to have multiple connection string in a single config file?

using connection strings in the report server than the datasource in 2005



I am using a datasource in the report server where all the reports use that shared datasource while calling the reports from asp.net pages.

Now, as asp.net pages uses the connection string for the databases which is assigned in the web.config file, i want the reports also use the same connection string because you don't need to change on both places( web.config and report server datasource).

Any idea plz

Connection Pooling VS Steady Connection in Windows Service Application


Hi All,

We are developing a windows service application which queries the sql db every second. For now, we have enabled connection pooling and every time we open and close connection at every access. Since it is a windows service can I open connection at service startup and close the connection shutdown

Please let me know the right approach in this scenario.





Service Application Connection: Managed Metadata Service is inaccessible


 Hello all,

I have published the MMSA in one farm so it can be connected to and consumed by another farm. The publishing farm URL is https (SSL) and the consuming farm is http (Non-SSL). The connection to the MMSA shows in Central Admin as succesful, however when I try to open the Managed Metadata in the term store in the consuming farm I get the following error:

"The Managed Metadata Service is inaccessible because the current web application has not been granted permissions to access it."

I followed all the steps in technet, including the certificate exchanges and the publishing farm MMSA has granted the consuming farm full control.


Any clues? Can a farm with SSL publish service applications to non-SSL farms?


Close DB Connection upon application termination?


The reason this question came up, is because if I run my website application with a SQL Server data store, and I terminate the browser (terminating the session), I try to open up SSMS to edit the DB.  But I can't access the database because I believe there is still an open connection, even after application termination.

Is it recommended to close the database connection upon session/application closing?  Or am I way off on what I'm thinking could be the problem?

Thanks in advance. :)

Using a pfx certificate to decrypt app.config connection strings


Hi, I am using both Azure & WinForms applications, with common libraries in .NET 4. I have encrypted my connection strings in my Azure app using the approach here: http://blogs.msdn.com/b/sqlazure/archive/2010/09/07/10058942.aspx  That is working fine, no issue with the Azure side (this is not an Azure question).

I have now encrypted the connection strings in my app.config file of my windows app, and have imported the .pfx certificate into my certificate store. When I run my app after just importing the certificate, it works fine. It decrypts the connection strings and works. After I reboot however, it fails because it does not have access to the private key in the .pfx file. I assume that's because the private key needs to be authenticated again.

I am a newbie to encryption, and although I've spent the past few days finding what I can, but I can't crack the right way to work with this.

How can I embed the private key in the .pfx file, so when I run the app on my development machine, it will have access to the private key & work?

Thanks, +M

Encrypt connection strings in web config




We have website hosted on shared server with SQL Server 2005 as database. Now that database server is also shared by other people and hence we have to use SQL Server authentication and we have stored those connection strings in our web.config file.


Can we encrypt connection strings? I found few ways to encrypt but in all of them I have to have access to the server and that I don't have.


Pls help.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend