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

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

Modifying connection String in Web config using Install Wizard

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net


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

View Complete Post

More Related Resource Links

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

<add name="ApplicationServices" c

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



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);

SSAS Deployment Wizard - Data Source connection string userid and Password getting removed



I have an SSAS database (Analysis Services 2005) which connects to Oracle for the data. I have the userid and password
saved in the connection string.


If I deploy the cube from Visual Studio I DON't have to manually edit the Data Source in the server to input the userid and password. The information is retained.


If I do a build and then deploy .asdatabase file using Deployment Wizard (Microsoft.AnalysisServices.Deployment.exe), the connection information dissappears. I have "Remove Passwords" = False in Project configuration. So when you build the project there will be a file with extension .assecurityinformation which holds the encrypted security info. Somehow

deployment wizard doesn't look at this file.


After the build I execute this command

Microsoft.AnalysisServices.Deployment.exe  .\Project.asdatabase /s:.\Deployment.log

I tried interactively and silent mode. Either way I cannot deploy the project with the userid and password in it.

Any clue?

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


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.

SQL Connection String

We can learn or know how can we connect the database from our .net. This will help for freshers or .NET beginners!

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

connection string question from a newbie


when publishing  in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"

I was not sure what it was so I pasted this from my web.config file :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True

it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.

My question is this, What should go in the field for "Destination connection string"

Custom security via connection string

Hi Is it possible to pass information into the SQL Server relational engine via the connection string in the same way as it can be done for Analysis Services? I need to generate a user context for a forms authentication application (i.e. no windows user accounts). SSAS allows you to pass in a list of database roles or a customdata parameter on the connection string. These can be used inside the database in lieu of a windows identity. I am wondering if there are equivalent parameters available for the SQL connection string.  I guess that I could create SQL logins from each of the forms users with a system generated password and then pass the uid and password on the connection string but this seems unnecessarily complicated. Andrew Wiles - www.it-workplace.com - MDX made simple

connection string

on the computer with sql management installed i use this and it works(server name):  .\SQLEXPRESS the computer name is: MAINCOMPUTER2 another computer on the network would use what? i can see  the c drives on either computer from either computer so i am connected.    

Connection string

Hi There!I am doing a project using Visual Web Developer Express. I have built a database using MS SQL Server Express which I have installed together with Visual Web Developer Express. Please help me what sort of the connection string I should use in the pages of my website to establish connection to the database.Thank you

Visual Studio SQL Connection Wizard - where are values stored?

I have a problem with the Configuration Manager and though clearing the cached information would help, but I can't find how to do that.The problem - No matter how many times I try to create a new connection to an existing database, the wizard retrieves an incorrect listing of the tables for that database (this is just one database it is happening with).  I try creating different users in SQL Management Studio (which shows the proper tables) and I can connect fine with the new user, but these incorrect tables keep appearing. This only applies to the aspnet membership tables that, at one point I had named with an extra prefix (eg vw_aspnet_Users) but are no longer named as such. Now, only the vw-prefix tables show up and they don't exist anymore. Also I have made some of my own tables (eg aspnet_User_Info) which don't ahow up at all. When I make other new tables though, they seem to show up fine. Also, if I manually construct the query through the wizard, it will properly access the tables that don't show up.So, Is there someone I can clear/refresh wherever this information is being cached? Removing everything from the Web.config does nothing, as Visual Studio seems to save the connections elsewhere (connection strings from other projects show up in the wizard as well)Any tips are appreciated

problem in connection string

i have problem in connection strin i host my siteand database is in DATA DIRECTORYmy site run successfully in offline but an error of connection string in online pls give me an example of string for onlinei use asp.net, C# and sqlserver 2005

How to change connection string of a pivot table pointing to SSAS 2005 cube using excel 2003?

Hi All,I am not sure if I should have posted this query to Excel 2003 forum. But posting it here as it applies to SSAS 2005 as well.Ok, let me give the background before I tell the actual problem.We have users on ABC domain and the SSAS server is also on ABC domain. Users on this domain can acess the excel pivots by connecting to cube to browse the data. They leave the Userid & password field blank while they setup the connection string and it works fine. Thanks to windows authentication that takes the credentials of user logged in. Let's say I have two users A and B, they login to ABC domain with their own windows ids.  Now when user A creates a excel file having a cube pivot and then sends this file to user B, user B can refresh and modify the same excel file (he can select new measures to pivot, new hierarchies in filters and so on).Now, let's say I have another user, user C. He has excel 2003 installed on his PC and cannot migrate to excel 2007. He is on different domain XYZ but have a valid windows userid on domain ABC. The domain ABC & XYZ can not be setup to have trusted relationship. Now, when user A sends the same excel file to user C. When user C opens the file and try to refresh it or try to modify the pivot by selecting/deselecting any elements, he gets below error prompt:" An error was encountered in the transport layer." and "Errors in the

help configure my connection string

i have created a linq to sql mapping classnow i changed the location of the server but i can't chane the connection string to the new location where can i do this ?HosDataContext db = new HosDataContext();             Sur_Accessory nor = new Sur_Accessory             {                 SurgeryAccessoriesID = Guid.NewGuid(),                 Kind = TextBox4.Text             };HosDataContext db = new HosDataContext();            Sur_Accessory nor = new Sur_Accessory            {                SurgeryAccessoriesID = Guid.NewGuid(),                Kind = TextBox4.Text            };this code brought error after changing the serverError 8 The type or namespace name 'HosDataContext' could not be found (are you missing a using directive or an assembly reference?) E:\WorksAndBackUps\Hospital\4-9-2010\MostafaRadyHospital\MostafaRadyHospital\Admin\Surgery\UCA_SurgeryRoom.ascx.cs 34 37 MostafaRadyHospital

Connection String of ActiveDirectoryMembershipProvider that points to servers of High Availabilty

I have 2 LDAP servers, A and B which are configured to high availability. When A fails, B will take over and vice-versa. How do I set the connection string of the ActiveDirectoryMembershipProvider in this case? Thanks in advance.   (P.S: I am using asp.net / VB.net, .net framework 2.0) 
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