Home » Silverlight

webconfig substitute variable

i have a lot of connection Strings in webConfig. and i test application in different places

is in possible create variable in webconfig like @MyDataSource="my_pc\sql2008r2"

and use it in connection strings like

<add name="dbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;

Data Source=@MyDataSource  instead of Data Source=my_pc\sql2008r2;

AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

after that i can change one line in wegconfig.


1 Answer Found


Answer 1

You can't do this directly, but there is a work around that works well.

You can modify the ConnectionStrings during the Application_Startup event in the Global.asax.  So the algorithm would look something like this:

- Add a MyDataSource key in the app settings

- In each of your connection  strings put a placeholder. Something like {MyDataSource}

- In the application  startup, spin thru the connection strings  (via ConfigurationManager.ConnectionStrings) and do string replaces with the value in the app settings.

That should get you done.  Now if you are using VS 2010, you can create  you multiple versions of the web.config (ie one for testing and one for production) to prevent you from having to go this route.

Hope this helps.





Hi, i am so happy now that we can use the Ribbon for our App.

i want to know if it's there any way to use an MDI with the Ribbon as Excel use it???

if there isn't. is there any substitute for MDI (something that works similar)???

One of our Students plans to take the Exam 70-680 and was hoping to avoid the 77-600 Exam for his MOS 2007 Certification. Is that a possible substitute? Thanks in advance ...


I have a pretty old application using MFC's CAsyncSocket. It runs as a service. It's clients used DDE to communicate with it. Due to the session 0 isolation starting with windows vista I have to modify the client side.

So I am on the way to replace DDE with COM. The ATL Project Wizard doesn't offer MFC support for services. All attempts to get MFC working with AfxWinInit failed.

Now I have two questions:

Is there a way to use MFC within an ATL service? If not, is there any substitute for CAsyncSocket in ATL?

Thank you for any hint



Hi Security Experts ,

Receintly , we had a situation where we were not able to login to SQL Server 2005 x86 on a cluster .The reason was that we had removed Builtin/Admin ....We had to add it back to bring the SQL Server resource up and running ...But due to Audit we cant keep Builtin\Admin and will have to remove it ...Is there a way to have a substitute for this ...I am sure there will be ..



In Visual C++ 2010, the /Za compiler switch is supposed to disable language extensions and help the programmer conform to standard C++. In particular, the C++ standard allows for the use of "and" instead of "&&".



When the /Za compiler switch is used the program compiles fine with "and", but Intellisense still reports an error on the line where "and" is used. Including the header <iso646.h> removes the error, but this should not be needed in standard C++.


We attempted to implement the Chapter 2 Framework from the Knight, Vermeen, Moss, Hackney book on SSIS 2008: Problem Design Solution. We see a couple of problem areas (at least) in our interpretation of the guidelines from the book.

1. We are attempting to have one connection string per server: dev/prod

2. We have set up environmental variables per server: dev/prod

3. We have set up XML Package Variables per server: dev/prod

4. We have set up System Variables per server in SQL Server: dev/prod

Problem 1:

We've had to manually key in the common connection string to all packages on a server environment in the component properties area (control flow; not data flow--ok there)

Shouldn't the connection property find the connection that we've instantiated and provide us with a pull down to select it?

The components are un-editable after we select the common connection string, but they still run properly in our SQL Server Agent Job.

Problem 2:

The dev server variable overlays the prod server variable information duringprod component editing

We are'nt sure if these problems are related.

Here is our package variable:



Here is our DTSconfig file; we have a few variations of this that we've tried.

<?xml version="1.0"?>
   GeneratedBy="MEDC\SSIS Team"
   GeneratedDate="9/20/2010 04:00:00 PM"/>
  <ConfiguredValue>Data Source=MEDC-SSIS\SSISSQL2008;User ID=sa;Initial Catalog=MedcDwProd;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;</ConfiguredValue>

I've validated the SSIS_Configurations table for data similarities in both dev and prod.

dev has:

CommonConfigurations Data Source=MEDC-SCCM-SQL\SCCMSQL2008;User ID=sa;Initial Catalog=MedcDwDev;Provider=SQLNCLI10.1;Integrated Security=SSPI; \Package.Variables[User::connMedcDwDev].Properties[Value] String

Prod has 2, since I've been experimenting with the SSIS_MEDC piece.

CommonConfigurations SSIS_MEDC \Package.Connections[SSIS_MEDC].Properties[Name] String    ***(Experimental)

CommonConfigurations Data Source=MEDC-SSIS\SSISSQL2008;User ID=sa;Initial Catalog=MedcDwProd;Provider=SQLNCLI10.1;Integrated Security=SSPI; \Package.Variables[User::connMedcDwProd].Properties[Value] String

Our goal is to make one change per server for the connection strings.

Some of this work was manually performed.

Anyone want to take a critical look at our framework?

Many Regardx,








What in Excel 2007 can be used?   Instead of, for example:

Pnt1_x = ExecuteExcel4Macro("get.chart.item(1,1, ""S1P" & i & """)")

It works; but you can't get the help files and understand the parameters if you don't not have Excel 2000 .






We have a multiple deployement environment which requires file sizes to be different depending on the server that is being deployed too. An example of what we are doing is

ALTER DATABASE [$(DatabaseName)]
    ADD FILE (NAME = [f1], FILENAME = '$(Path2)$(DatabaseName)_1.ndf', SIZE =[$(FGSize)] , FILEGROWTH = 1048 KB) TO FILEGROUP [FG1];

where $(FGSize) is the substitution. Currently we get the following message

SQL02010: Incorrect syntax near [$(FGSize)]

Is this sort of substitution possible within VS2010 DB project?



For IBulkCopy,  do we just have to add the contents  under "<microsoft.applicationServer>" to web.config?

or Do we also need to implement IBulycopy in code?

Please reply ASAP

hi every one ,
while building my Asp.net Mvc solution i am getting following error:

"The type or namespace name 'HostelerDBEntities' could not be found (are you missing a using directive or an assembly reference?)"

Here  "HostelerDBEntities" is entity Connection setting in webconfig

i am not sure why it is coming 
can any one help


this avoids a MAC error

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

I add this to webconfig and it works

<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false">

why does it work and what an earth is this error as it makes no sense to me. it is to do with sessions.

HI EVERYONE, I'm dealing with a big problem trying to deploy the ifd with a current CRM 4.0 deployment. The status is that i can get the signin page after type the url. I've check all the changes that the tools make after running it, and it seems that the ifdsettings node is missing in my webconfig file, i'd tryed to put in there manually but the asynchronous service stopped, i don't know where and how to put that node in orer to enable ifd. any suggestions???

My Web.config customErrors  section is given below


How can I exclude a aspx page from DefaultRedirect, if errors occur in that page?

thanks in advance...



Have deployed a web application that works fine on another server.

But when I deploy it on a test server (that has been changed recently) i get a error in webconfig.
The problem is that i can't access the server to se what framework is installed on it. I can only access it thru ftp.

Now as i can se the error says framework 1.1 but can I assume that 2.0 or above is NOT installed ?

Some of the error is:

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: WebDataGrid
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/root/f132559d/864240f2/WebDataGrid.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/root/f132559d/864240f2/WebDataGrid/WebDataGrid.DLL.

Version Information: Microsoft .NET Framework Version:1.1.4322.2443; ASP.NET Version:1.1.4322.2460


Thanks in advance




I have created the asp.net application and Hosted on Different Server(i.e Test,Development). its is an Intranet Application

But When I tried to Host on Production the WebApplication dont work when I check the "Integerated Authentication"

and when I check the "anonymous Access" i get null  value for

the HttpContext.Current.User.Identity.Name.ToString() returns null .

and User.Identity.IsAuthenticated also return false.

 what changes do I have to make in IIS and Webconfig of my application so that it can run on ProductionSERVER



Hi there,

I have an ASP.net website running with the authentication mode on the web.config file is Windows.  The webpages at the root do not need to have login & password form.

Now I created a subfolder called 'reports' and would like to implement a few web pages with the login & password authentication form. 

Question, do I need to create another web.config file in the 'reports' folder and update the authentication mode="Forms"?  Any ideas?

Your help is much appreciated.  Thanks.






We have a vs2005 solution including 2 websites. We converted the solution to vs2010 and changed all settings in IIS and in the config file to use framework 4.0. We removed the old assembly references in webconfig file and added references to the new versions of the assemblies. And here the problem comes. When we add a refererence to System.Design assembly in the webconfig file the website does not build. The build via msbuild.exe results in the following error:

ASPNETCOMPILER : error ASPPARSE: Object reference not set to an instance of an object. [d:\DevSites\SolutionFolder\WebSite.metaproj]

Does anyone have any suggestions why this happens ?



Hi All,

  I had a question about the cookieless attribute found in the web config file for the forms authentication and the session state nodes.

    If I set the cookieless attribute  to 'UseDeviceProfile', do session state and forms Auth use cookies or not? According to the microsoft documentation, the browser is checked whether it supports cookies or not, and if it does not then the url is rewritten. I do not understand what 'url is rewritten' means.

Another question, I changed my browser settings to block all cookies and still my forms authentication cookie works. How is that? I thought cookies can be blocked by browsers.


Please help me this is not an easy question.

This is the first time I did not get my answer.

I tried this:

Dim str1 As String = Nothing

        Dim int1 As Integer = Nothing

Dim hValue as String = (Number from data base)  

Dim add as Integer     

str1 = hValue

        int1 = Convert.ToUInt32(str1)

        add = (add + int1)

        textbox1.Text = add


Can someone point me to where I am going wrong with this statement, I know it must be very simple but I am going crazy:


This is the table:

CREATETABLE [dbo].[Globals](

      [Name] [varchar](64)NOTNULL,

      [Value] [varchar](7500)NULL,



      [Name] ASC




All I want is to pass in the database name (this is part of a job that will be run across hundreds of databases, one at a time)

And get back the value to pass into the variable.


Declare @DBName varchar(100)

Set @DBName = 'MifisiteTest'

declare @AllowOverallNarrative int

Execute( 'set ' + @AllowOverallNarrative + '= convert(int,Value) from ' + @DBName + '.dbo.Globals where Name = ''AllowOverallAssessmentNarratives'')


.Net SqlClient Data Provider: Msg 102, Level 15, State 1, Line 5

Incorrect syntax near '.dbo.Globals where Name = 'AllowOverallAssessmentNarratives')'.



--Also tried it with the below

Set @AllowOverallNarrative = ('Select convert(int,Value)as AON from ' + @DBName + '.dbo.Globals where Name = ''AllowOverallAssessmentNarratives'')'


.Net SqlClient Data Provider: Msg 102, Level 15, State 1, Line 5

Incorrect syntax near '.dbo.Globals where Name = 'AllowOverallAssessmentNarratives')'.



Any assistance appreciated,




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure