I have a web.config file, in connection string attribute, I have an '&' in password which creates error in parsing web.config file.
code:
<connectionStrings>
<clear/>
<add name="FamefaceDB" connectionString="Data Source=ec2-204-236-162-54.us-west-1.compute.amazonaws.com;Initial Catalog=famefacedb;User ID=Administrator;Password= t2kfPcn6?D& "/>
</connectionStrings>
The '&' in password is illegal and says hexadecimal value is illegal in XML file.
Is there any solution to this?
XML is XML and web.config must be valid XML - a "literal" & must be written as &1
Compare with the correct entity encoding:
<add connectionString="..;Password=t2kfPcn6?D&"/>
1See Which are the HTML, and XML, special characters? (linked by Noel in a comment) for the gritty details.
Related
What is the format (if any) for adding user name and password to neo4j v4 connection strings? So far, I've seen just examples like bolt://localhost:7010 with authentication being added as extra arguments to the connection calls.
Here's why I'm asking:
I have an ASP.NET app which connects to both MS SQL and neo4j DBs. For MS SQL, I can add the connection string to the /configuration/connectionStrings in web.config formatted like this
<add name="MyDB" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;UID=user;PWD=pwd" />
or
<add name="MyDB" connectionString="Data Source=.,1433;Initial Catalog=MyDB;UID=user;PWD=pwd" />
It contains host name, instance name or port name, plus the credentials. I can then encrypt the connectionStrings part of web.config using standard IIS tools.
For ease of management, I'd like to reuse it for neo4j connection strings as well. I could store the string in MSSQL-like format
<add name="MyNeo4jDB" connectionString="Data Source=.,7010;UID=user;PWD=pwd" />
but I don't want to invent my own format.
Thanks
I'm using EF code first approach in MVC and my web.config's connection string looks like-
<connectionStrings>
<add name="SchoolContext" connectionString="XYZ-server;integrated security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
And I'm getting following error-
Server Error in '/' Application.
Could not determine storage version; a valid storage connection or a
version hint is required.
I also checked duplicates but none of them worked in my case-
Duplicate question1
Duplicate question2
I solved the issue by looking closely to the connection string, actually data source was missing, correct one is-
<add name="SchoolContext" connectionString="Data Source=XYZ-server;integrated security=True;" providerName="System.Data.SqlClient"/>
<appSettings>
<add key="myKeyName" value="DFG&y:yd%yeZ" />
</appSettings>
I have a web.config file in an ASP.NET MVC application. In my appSettings section, i have a key whose value contains a character that makes the web.config invalid.
The character is the "&" in value="DFG&y:yd%yeZ", if i remove it, the app works fine, when i put it back i get the error below.
Configuration Error Description: An error occurred during the processing of a configuration file required to service this request.
Please review the specific error details below and modify your
configuration file appropriately.
Parser Error Message: An error occurred while parsing EntityName. Line
25, position 61.
And my key below is highlighted in red.
<add key="myKeyName" value="DFG&y:yd%yeZ" />
Is the "&" prohibited in the a web.config's appSettings key Value?
You need to replace the special char "&" by:
&
Here is a list of special chars
I already finished my first c# application which manages some tables on a sql server 2005,but I want to modify it so that it could read the connection string from a text file . By doing that I can move my application to another PC by only changing the connection string in the text file and avoid any change in the code itself. How can I do this?
Take a look at System.Configuration (http://msdn.microsoft.com/en-us/library/system.configuration.aspx). There are some built in methods for reading configuration files (App.Config)
You should use the connectionStrings section in your app/web.config file:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-EditorTemplateCollectiosns-20130404170435;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-EditorTemplateCollectiosns-20130404170435.mdf" />
</connectionStrings>
Then, when you want to access it in code, do this:
var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"];
More on ConfigurationManager here, on configuration files here.
if you are developing desktop app, the preffered place is app.config
<connectionStrings>
<add name="TailorShop.Properties.Settings.TailorShopConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=TailorShop;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Notice the connection name here, coz it is defined in the properties (double click on the properties node in your project solution explorer and go to settings)
And then you can add your connection string there. After that you will see as shown above;
Now, in-order to access it, you can do this in code;
Settings.Default.TailorShopConnectionString
In-order to work this code, you must add a reference e.g yourprojectname.properties;
using TailorShop.Properties;
You can manage your connection strings from a dedicated configuration section in your App.config file. Look here for more information on this.
Instead of using plain text files on non-standard solutions, see what .NET already provides. You can change the value in the config file when you move the application without needing to recompile it, because config is being read at runtime.
Here is an example:
<configuration>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=.;Initial Catalog=MyDatabaseName;IntegratedSecurity=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Access it from code using ConfigurationManager.ConnectionStrings["MyConnectionString"].
If you really have to use a text file, then you should take a slightly different approach.
First you have to use a fixed path on the filesystem for the connection string file. You can either hardcode it in your app - a BAD PRACTICE, or use Settings or the App.config file to define the text file path.
You have to read the file programmatically. If it is plain text, you can use System.IO.File.ReadAllText(filePath); where the filePath argument is the absolute path to the file. For having the need to change the path when compiling the app, you can use the configuration/settings approach to define the physical path to the file, since changing them will not require recompilation (as earlier addressed for connection strings)
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Sections must only appear once per config file. See the help topic for exceptions.
<connectionStrings>
<add name="testEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ROCKER\SQLSERVER2008;Initial Catalog=test;User ID=sunny;Password=sunnyconnected;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<add name="DbConnection" connectionString="Data Source=Test\sqlserver2008;database=test;User ID=sunny;Password=sunnyconnected" providerName="System.Data.SqlClient"/>
This Connection String Set in Root Web.config File then it give runtime Above Mention Error.How it Can be Handle And Set in Asp.Net MVC2.
"connectionStrings" section should appear only once in a config file. Check if you have added it twice.