.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

Using web.config settings in a

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

Hi there,

I understand that one can specify a connection string in an <asp:SqlDataSource /> tag, like so:

<asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:LiveConnectionString %>" SelectCommand="SELECT Col1 FROM MyTable"></asp:SqlDataSource>

Is there a similar way to specify the table used in the SELECT command?  The following doesn't work for me:

<asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:LiveConnectionString %>" SelectCommand="SELECT Col1 FROM <%$ AppSettings:NewContentsListSQLTable %>"></asp:SqlDataSource>

I see from a previous post (http://forums.asp.net/p/1325626/2646097.aspx) that it's possible to set parameter values from web.config settings, so I'd hope you could specify the table (or columns etc.) as well!

All advice gratefully received.

View Complete Post

More Related Resource Links

Convert user.config to database storage via my custom settings provider



I've created my own custom settings provider to save user settings (formerly in the user.config) to a database. To point the particular settings that are to be saved to the database I specified

for each property to point to the BlobSettingsProvider instead of allowing them to default to the LocalFileSettingsProvider.
Now I need to convert existing user.configs to save to the database on the fly - a one time conversion. Because I've now specified the properties to use the BlobSettings provider they can no longer access the local user.config.
Does anyone have any thoughts on how best to accomplish this conversion (i.e. read the local user.config and populate the BlobSettingsProvider). The app can be run as a ClickOnce installed app or as a simple .net app - finding the correct local user.config looks to be a problem.
Thoughts, ideas,...?


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


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!






xml version

Reconnect WCF klient useing app.config settings




I have a webservice with a reconnect button in the client. I'd like to implement the reconnect function. I have seen a lot of example how to reconnect but all of them implements it with setting the endpoint and everything in the code.

When open my client it uses the app.config settings to open the WCF channel. Actually I'm not a developer so I don't really understand how. I just instantiating my implemented webservice class and it do the job itself.

Is it possible to reopen channel / reconnect using the app.config settings without setting everything in code? Or do I have to set in the code every parameter?




I'm not a development! I'm an infrastructure engineer! Please be patient on the development forums! :)

hard code app.config settings in class



I wonder how to hard code the configuration below in a class. I have a case where I cannot use app.config (due to creation of dll).  The code below is probably not enough..any help is appreciated. Thanks in advance.

hard coded in class

ContractDescription contract = new ContractDescription("Common.MyInterfaces.IConnector");

Binding binding = new NetTcpBinding();

binding.Name = "net.tcp.binding";

EndpointAddress endPointAddress = new EndpointAddress("net.tcp://localhost:9001/Connector");

ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contract, binding, endPointAddress);






        <binding name="net.tcp.binding"></binding>





        <behavior name

web.config has incorrect settings for the requestFiltering element


HI! When I upgrade from wss 3.0 to sharepoint foundation 2010, i find this error and the error is shown below:

Web.config file has incorrect settings for the requestFiltering element.

The requestFiltering element in web.config must have the allowDoubleEncoding attribute set to true in order to support file names with the + character in them. Also, it must have a child requestLimits element with the maxAllowedContentLength attribute set to 2147483647 to avoid interfering with file uploads.

Ensure the requestFiltering element exists in web.config, that its allowDoubleEncoding attribute is set to true, that it has a child requestLimits element, and that its maxAllowedContentLength is set to 2147483647. For more information about this rule, see "http://go.microsoft.com/fwlink/?LinkID=163442".


In the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\web.config, the maxAllowedContentLength is already set to 2147483647. 

Does anyone have any idea?


Service throttling behaviour app.config settings

How can I calculate the MaxConcurrentSessions, MaxConcurrentCalls and maxConcurrentInstances properties to set in the app.config ? I believe it should have some dependency on the # of CPU and the Max and Min worker threads based on which these parameters can be set.

Can you please guide me how can I provide them the number for these properties like we could calculate for ASP.NET.

Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we've added over the years, including the functionality for:

.ASP.NET Dynamic Data
.ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
.ASP.NET Chart Control (which now ships built-into ASP.NET V4)
What this means is that when you create a new "Empty ASP.NET application" project in VS 2010, you'll find that the new default application-level web.config file is now clean and simple:

Convert English to Arabic number without changing any regional settings in .net

Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

validateRequest appears to be kicking in in MVC RC1 despite settings

After upgrading a project to the RC a System.Web.HttpRequestValidationException is thrown when posting a value containing HTML from a TextArea. I have checked that validateRequest=false in Views/web.config, and have set this in the application's root web.config. I have also created a fresh MVC project, created a simple view & controller and posted a simple html paragraph element with the same result. Call stack provided. [HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (html="

hello world

").] System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +8718538 System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +111 System.Web.HttpRequest.get_Form() +129 System.Web.HttpRequestWrapper.get_Form() +11 System.Web.Mvc.ValueProviderDictionary.PopulateDictionary() +113 System.Web.Mvc.ValueProviderDictionary..ctor(ControllerContext controllerContext) +74 System.Web.Mvc.ControllerBase.get_ValueProvider() +31 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +53 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +109 System.W

How to retrieve data from SqlDataSource and pass to a variable?


Hi there,

I have a page in my website where there is very little code-behind. I only have two lines of code in Page_Load() and the rest of the code is declarative ASP.NET code. I have a FormView control which uses a SqlDataSource to get some order information. The SqlDataSource calls a stored procedure called usp_GetOrderDetails, here's the code for the SqlDataSource:

    <asp:SqlDataSource ID="sdsFormOrderDetails" runat="server" 
ConnectionString="<%$ ConnectionStrings:ForexDB %>"
ProviderName="<%$ ConnectionStrings:ForexDB.ProviderName %>"
SelectCommand="usp_GetOrderDetails" SelectCommandType="StoredProcedure"
UpdateCommand="usp_UpdateOrder" UpdateCommandType="StoredProcedure"
<asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedDataKey.Value" />
<asp:ControlParameter Name="orderId" ControlID="frmOrderDetails" PropertyName="SelectedValue" />

Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

SqlDataSource how to change the stored procedures at run time



Is it possible to change the select, insert and update stored procedure of an SqlDataSource at run time. I don't mean to change the definition of the stored procedure, but I mean to change the assignment, i.e. To change the select stored procedure from "selectSP1" to "selectSP2" at run time. Is it possible?



SqlDataSource UpdateCommand using 2 tables


I have two tables

Trans  with fields TransID, Date, CustomerID and some other stuff

Customer with fields CustomerID, Name, TaxId

On the screen the user only sees the fields Date and Customer Name. CustomerID is behind the scenes only.


I'm using SqlDataSource. Having no problems with SelectCommand. I don't know how to construct the UpdateCommand and InsertCommand.

Let's say the user changes the date, then I need to do an UPDATE.

UPDATE Trans SET Date = @Date, CustomerID = @CustomerID results in an error message and the record is not updated.

I get an error on the page that says "Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in correct format".


I tried taking out the set for CustomerID and I still get the error on page.


Also, for inserting, the users will see a dropdownlist with Customer Names. I need to convert that to a CustomerID to be used in the new record being inserted in the database. I'm not sure how to do this.


Do I need to do something with Control Parameters?

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

NUnit and config files


Ive created an NUnit test project in my solution and have added 3 tests.  They all fail with the same error

SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.


SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.

  ----> System.NullReferenceException : Object reference not set to an instance of an object.

heres the test method

        public void CreateDataContext_ConnectionString_ReturnsDataCon

Modifying connection String in Web config using Install Wizard



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