Here is my app.config
<configuration>
<userSettings>
<MyProject.My.Settings>
<setting name="IP">
<value>127.0.0.1</value>
</setting>
</MyProject.My.Settings>
</uesrSettings>
</configuration>
I tried :
My.Settings.IP
and
TryCast(ConfigurationManager.GetSection("FormProcessing.Designer.My.MySettings"),My.MySettings)
I also tried many other ways and went through so many sites but still didn't get any way to work. I don't want to move it to as well.
This should work
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<MyProject.Properties.Settings>
<setting name="IP" serializeAs="String">
<value>127.0.0.1</value>
</setting>
</MyProject.Properties.Settings>
</userSettings>
</configuration>
Call it MyProject.Properties.Settings.Default.IP
However, the easiest way to create a Property should be, go to menu View / Solution Explorer. Navigate to [Your solution] / [Your project] / My Project / Settings.settings and double click Settings.settings. On the left panel go to Settings. Add a row Name IP, Type String, Scope User, Value 127.0.0.1. On the top there is an access Modifier, I will leave it as friend. Then just use [Your Project].Properties.Settings.Default.IP
Related
I recently rewrote a large program that my company uses to conduct business. I changed to Entity Framework early on. For the most part it has been working quite well.
One issue that has annoyed me for quite some time and now I have time to look into is, a custom control that pulls a question from the database causes a strange error.
When the custom control used SQL it would actually show the question on form display in the designer. At first this was pretty cool and I liked it. After switching it to use Entity Framework 6, when I load the form in the designer I get the error
No connection string named 'wotcDB' could be found in the application
config file.
It's totally in the app.config file. In fact the program has no problem compiling and running without issue. For the longest time I would just push Ignore and go to work on the form. The question of course no longer shows up in the designer.
The User Control is part of the application. The app.config file is there, and the program both runs and deploys fine. What's causing this?
Here is my app.config, ####### is sensitive data.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="webDB" connectionString="metadata=res://*/Data.webDB.csdl|res://*/Data.webDB.ssdl|res://*/Data.webDB.msl;provider=MySql.Data.MySqlClient;provider connection string="user id=#######;password=#######;server=#######;database=#######;persistsecurityinfo=True""
providerName="System.Data.EntityClient" />
<add name="wotcDB" connectionString="metadata=res://*/Data.wotcDB.csdl|res://*/Data.wotcDB.ssdl|res://*/Data.wotcDB.msl;provider=System.Data.SqlClient;provider connection string="data source=#######;initial catalog=#######;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
Rather than deal with the issue, since only I see it. I've found an answer at
This Stack Article
I put
If (System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime) Then
Load_Question()
End If
in the custom control load. I don't see the question during design time, which is fine for me. My other option was to put the connection string into the EF class, which is difficult to keep up since I'm using EF-Design and not code first.
I have had always problems deploying MVC 4 web applications in any platform, getting it working after a lot of hours. However, at this time, I have found other new problem with an installation in Windows Server.
The error I am getting is that web.config file is not a well formed XML document. Microsoft pages, as usual, does not provide real solutions to the problems with its software. It only shows that I have not a well formed XML document, what is not true. That web.config is the same file I use in my development machine.
I installed the application in a folder named C:\Folder\Website, which has read permissions for user IUSR.
I have ran "aspnet_regiis -i" command
I have used local Administrator account for the application pool
I have used iisreset
Nothing helps
Can you help me to resolve this issue, please?
Regards,
Jaime
EDIT:
By using IIS 7 management console, and trying to change some configuration, the same error occurs, mentioning that the problem is at line 3 of web.config.
This is the start of web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
</sectionGroup>
</configSections>
I have had to grant IUSR both read and write privileges. Try that?
I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.
Thanks
You can put the configuration settings for any library in the main web.config. It's easy!
Connection strings are especially easy. Just add your connection string to the connectionstrings section with the same name it has in the library's app.config, and you're done!
<connectionStrings>
<add name="Sitefinity" connectionString="your connection string"/>
</connectionStrings>
To add configuration settings, at the top of your web config, find the applicationSettings section, and add your section's info. Note: be sure to set your library's settings access modifier to "Public". You can do this in the Properties ui.
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Your.Assembly" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
Then, add the section under applicationSettings.
<applicationSettings>
<Your.Assembly>
<setting name="TestSetting" serializeAs="String">
<value>a test value</value>
</setting>
</Your.Assembly>
</applicationSettings>
I have a WCF service with a setting I created in the WCF application property editor (settings tab).
It has created something like the following property in MySettings class in the Settings.Designer.vb file. Notice the DefaultSettingValueAttribute is set to "This is the OLD value". That's my value for local testing.
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("This is the OLD value")> _
Public ReadOnly Property Information() As String
Get
Return CType(Me("Information"),String)
End Get
End Property
On the production server I have changed the web.config file as below. The "NEW" value would be useful for the production server. It represents a connection string, or production resource address.
<applicationSettings>
<setting name="Information" serializeAs="String">
<value>This is the NEW value</value>
</setting>
</applicationSettings>
The problem is after restarting the WCF service (rebooting the server machine completely), it never reads the new value. It continues to use the old value that was set as the default value in the designer file.
I think this must have to do with file permissions, but I don't see anything in the event log that indicates a problem. It's like the WCF service isn't even trying to read the web.config file. I don't find anything like this problem on Google and I've run out of search term ideas.
Why isn't the service reading the settings value from the web.config file?
Did you make sure to add the SectionGroup to the ConfigSections of the production web server?
It should look something like:
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyWCFService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
and your application settings section should look something like:
<applicationSettings>
<MyWCFService.My.MySettings>
<setting name="Information" serializeAs="String">
<value>This is the NEW value</value>
</setting>
</MyWCFService.My.MySettings>
</applicationSettings>
I want to know how make NHibernate store my queries at 2-nd level cache for specified time
I see it only for entities cache.
Thank you for replying.
The query cache is not enabled by default. To enable it in your hibernate.cfg.xml:
<add key="hibernate.cache.use_query_cache" value="true" />
You should specify a cache region for queries. If not specified, the region will be "NHibernate.Cache.StandardQueryCache".
Session.CreateCriteria<User>()
.SetCacheRegion("UserQuery")
.List();
For syscache, cache regions are configured in you app.config:
<configuration>
<configSections>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" />
</configSections>
<syscache>
<cache region="User" expiration="300" priority="3" />
<cache region="UserQuery" expiration="60" priority="3" />
</syscache>
</configuration>