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


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

Encrypt connection strings in web config

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net
 

Hi,

 

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.

 

Anand




View Complete Post


More Related Resource Links

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


Modifying connection String in Web config using Install Wizard

  

Hey,

Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a lot of articles on how to do this and in particular this http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors,  heres part of my code where the errors are



using System;
using System.Configuration;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.DirectoryServices;

 void ConfigureDatabase(string targetSite, string targetVDir, string connectionString)
        {
            // Retrieve "Friendly Site Name" from IIS for TargetSite
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSit

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


Writing connection string in web.config file by code or dynamically

  
I want to write connection string in web.config file of my application by code. If anyone know the way or code just help me..NET,C#,SQL SERVER

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?

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

  

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<

Encrypting config file's connection string and keys

  

 Is aspnet_regiis.exe secure? If i encrypt using aspnet_regiis.exe, will it automatically decrypt the string and wont give any error? Need an insight into this stuff....any suggestions? Is Rsa the best option or wat? Wat's the best way to encrypt/decrypt programmatically?


web.config connection string problem within VisualStudio 2010 to point to SQL Server 2008 R2 Develop

  

Hello All, I would appreciate any help with this.

I believe my problem exists within the web.config which already had code in it to connect to SQL Server Express 2008.

I uninstalled the SQL Server Express that came with Visual Studio 2010.

I installed SQL Server 2010 R2 Developer, and I'm able to connect via Management Studio and through Visual Studio's Server Explorer's Data Connections I am connected.

I did run aspnet_regsql.exe within the 4.0 folder in order to create the database with Microsoft Service Providers.

Here is the ServerName: USER-5529234649 

Here is the name of the DataBase:  StepByStepChapter9

Here is the name of the Connection within Visual Studio's Server Explorer's Data Connections:  user-5529234649.StepByStepChapter9.dbo

Here is the code I changed in the web.config:

<connectionstrings>
<add name="ApplicationServices" c

Web config connection string error: a field initializer can not reference the nonstatic field

  

Hello:

I am try to get connection string from web config, but I got error" a field initializer can not reference the nonstatic field, method, or property '_default.connStr'. I search a lot. It says that I need constructor, but I am not sure how to write the constructor at class: public partial class _Default : System.Web.UI.Page


Here is my code:

{public partial class _Default : System.Web.UI.Page

    string txt;
    string username;
    OleDbCommand myCommand = null;
    OleDbDataReader myDataReader = null;
 

//retrieve the connection string from the ConnectionString Key in Web.Config
    string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    //create a new OleDB connection
    OleDbConnection myConnection = new OleDbConnection(connStr);

protected void Page_Load(object sender, EventArgs e)
    {

            string strOledb = @"select * from tableone";
     
            OleDbCommand myCommand = new OleDbCommand(strOledb);

n-tier, configuration info, specifically connection strings

  

Folks,

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?


encrypt App.config

  
How can I encrypt the entire App.config instead of encrypting just the aaSetting or ConnectionStrings only?



Jassim Rahma

Encrypt App.config for SMTP settings

  

Hi all,

I need to encrypt SMTP settings in the app.config file.I also read MSDN article that uses RSA also to encrypt/decrypt.
This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;


namespace EncryptionDecryptionCA
{
  public class Program
  {
    private static void ProtectConfiguration()
    {
      // Get the application configuration file.
      Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

      // Define the Rsa provider name.
      string provideRsa = "RsaProtectedConfigurationProvider";

      //

First WCF Connection Slow and Proxy Settings in app.config file

  
Hi,

I'm new to the WCF and currently facing problems with my first connection to a service we created to connect an Excel OBA to SAP. The first connection is extremely slow, approximately 20 seconds, but once it is establish everything goes really quick afterwards. I've read through some posts and seems like the proxy settings could have an impact. I'm pasting the code of my app.config file below, can you please let me know how I should modify it to include proper proxy settings to improve the first connection?

Also, the proxy thing is just a guess, is there anything else I could do to improve this? Any hint would be appreciated.

Thanks a lot!
Martin

<?

<

</

<

</

xml version

Is a Dynamic Config Possible for SSAS BIDS Projects? (Data Source / Connection, and Deployment Targe

  

How do we automate SSAS Project configs such that (a) RDBMS data source server (connection) and (b) SSAS deployment target server are dynamic? 

As it stands, just before I script the ASDB (for deployment/promotion from Dev to QA, or QA to Prod, for example), I use BIDS designer interfaces to change the source connection and deployment targets, then script the ASDB. 

Is there a more dyamic alternative?  Perhaps something analogous to SSIS package configurations?  I can't believe that everybody is doing this as manually as I've done.


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

  

Hi!

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


[SOLVED] .Net 2 Service unable to access Connection String in Machine.config

  
I have a Windows Service I have developed in Visual Studio 2005 (C#).

It accesses a database using a connection string in machine.config.

On my Windows XP Pro 32bit (SP3) machine, it works correctly.

On my new Windows 7 Pro 64bit machine, it throws "object not set to an instance of an object" when it gets to the line where it's trying use the connection string.
This is the 'object' which is not set in Windows 7:
ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString

 

The machine.config has the same connection string set up on both machines.

A .Net 2 website transferred to the Windows 7 machine has no problem accessing the same connection string.

I have tried a bunch of different permissions on the machine.config and its containing folders, and setting the service to log in as Admin, but I don't know exactly what permissions are required.

Does anyone know what's going on here? Many thanks.


Categories: 
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