-
asp.net web.config and spring.net config file - passing key values between them
I have following web.conf file in one asp.net app:
<code>
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler , Spring.Core"/>
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSecti onHandler, Spring.Core"/>
</sectionGroup>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHa ndler,log4net"/>
<section name="DatabaseConfiguration" type="System.Configuration.NameValueSectionHandler , System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!--
<section name="DatabaseConfiguration" type="System.Configuration.NameValueSectionHandler "/>
-->
</configSections>
<DatabaseConfiguration>
<add key="connection.string" value="Data Source=LU2009;Initial Catalog=CC_INF;Integrated Security=True;uid=xxx;pwd=xxx;"/>
</DatabaseConfiguration>
<spring>
<context>
<resource uri="~/Config/App_Spring.xml"/>
</context>
</spring>
...
</code>
And I have spring config file, app_spring.xml:
<code>
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<object id="autoProxyCreator"
type="Spring.Aop.Framework.AutoProxy.DefaultAdviso rAutoProxyCreator, Spring.Aop">
</object>
<object id="attributeTransactionAttributeSource"
type="Spring.Transaction.Interceptor.AttributesTra nsactionAttributeSource, Spring.Data">
</object>
<!-- ============== SQL Server db ================== -->
<object id="bn_dbProvider_indb"
type="Spring.Data.Common.DbProviderFactoryObject, Spring.Data"
lazy-init="true">
<property name="provider" value="SqlServer-2.0" />
<property name="ConnectionString" value="${connection.string}"/>
</object>
...
</code>
And I got the following errors:
Spring.Data.CannotGetAdoConnectionException: Could not get ADO.NET connection. ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
at System.Data.Common.DbConnectionOptions.GetKeyValue Pair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
at System.Data.Common.DbConnectionOptions.ParseIntern al(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(Strin g connectionString, Hashtable synonyms, Boolean useOdbcRules)
at System.Data.SqlClient.SqlConnectionString..ctor(St ring connectionString)
at System.Data.SqlClient.SqlConnectionFactory.CreateC onnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory.GetCo nnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at System.Data.SqlClient.SqlConnection.ConnectionStri ng_Set(String value)
at System.Data.SqlClient.SqlConnection.set_Connection String(String value)
at Spring.Data.Common.DbProvider.CreateConnection() in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Common\DbPro vider.cs:line 85
at Spring.Data.Support.ConnectionUtils.DoGetConnectio n(IDbProvider provider) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Support\Conn ectionUtils.cs:line 148
at Spring.Data.Support.ConnectionUtils.GetConnectionT xPair(IDbProvider provider) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Support\Conn ectionUtils.cs:line 103
--- End of inner exception stack trace ---
at Spring.Data.Support.ConnectionUtils.GetConnectionT xPair(IDbProvider provider) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Support\Conn ectionUtils.cs:line 107
at Spring.Data.Core.AdoAccessor.GetConnectionTxPair(I DbProvider provider) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Core\AdoAcce ssor.cs:line 156
at Spring.Data.Generic.AdoTemplate.Execute[T](IDbCommandCallback`1 action) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Generic\AdoT emplate.cs:line 315
at Spring.Data.Generic.AdoTemplate.QueryWithResultSet Extractor[T](CommandType cmdType, String cmdText, IResultSetExtractor`1 resultSetExtractor) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Generic\AdoT emplate.cs:line 884
at Spring.Data.Generic.AdoTemplate.QueryWithRowMapper Delegate[T](CommandType cmdType, String cmdText, RowMapperDelegate`1 rowMapperDelegate) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Generic\AdoT emplate.cs:line 847
at InfComm.Dao.Sqlserver.CommDao_sqlserver.GetListIp_ Addr(String where_str) in C:\c#\vs2010\mvc\av_arrival\InfComm\InfComm\Dao\Sq lserver\CommDao_sqlserver.cs:line 190
at Inf_CheckIn.Models.Services.AppService.GetListIp_A ddr(String where_str) in C:\c#\vs2010\mvc\av_arrival\Inf_CheckIn\Inf_CheckI n\Models\Services\AppService.cs:line 87
at CompositionAopProxy_4150504641c649f59934ad20c880b2 f2.GetListIp_Addr(String where_str)
at Inf_CheckIn.Controllers.LogonController.Logon() in C:\c#\vs2010\mvc\av_arrival\Inf_CheckIn\Inf_CheckI n\Controllers\LogonController.cs:line 60
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(Cont rollerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(C ontrollerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActio nMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__Displa yClass15.b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActio nMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__Displa yClass15.<>c__DisplayClass17.b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActio nMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActio n(ControllerContext controllerContext, String actionName)
If I place the connection text in the value instead of substitution, it works just fine.
Any help?
-Henry
-
Can you verify that if you place the contents of your app_spring.xml file into the web.config file that the substitution works as expected (e.g. that its really an issue with having the value set in one file and then referenced in another)?
-Steve B.
-
Is this all of your config or is there more? In reviewing this, I notice that there doesn’t seem to be any reference to VariablePlaceholderConfigurer or PropertyPlaceholderConfigurer in the config so the infrastructure to replace the ${..} expression isn't available to the container.
-Steve B.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules