Web Deploy removing quotes in connection string - entity-framework

The last quote escape is being removed in the webserver web.config when using webdeploy.
Any ideas why?
I've currently having to log on to the server and readd it everytime I publish the site!
<add name="Entities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="server=server;database=db;user id=1;password=password;MultipleActiveResultSets=True;App=EntityFramework;"" providerName="System.Data.EntityClient" />
becomes:
<add name="Entities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="server=server;database=db;user id=1;password=password;MultipleActiveResultSets=True;App=EntityFramework;" providerName="System.Data.EntityClient" />

Try to remove ";" (semicolon) before
&quot
try this,
<add name="Entities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="server=server;database=db;user id=1;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

Related

Store Azure WebJobs connection string on to Azure Portal App Settings

I'm trying to store the Web Job connection strings on to Azure Portal. I've moved the connection strings there but Web Job keeps failing with error below:
[03/05/2021 01:59:23 > 2aff49: INFO]
stem.ArgumentException: ConnectionString should not be null, and empty string or consists only of white-space characters..
This is how I've setup:
And app config:
<connectionStrings configBuilders="connectionStringsBuilder">
<add name="xdb.marketingautomation" connectionString="" />
<add name="xdb.referencedata" connectionString="" />
<add name="messaging" connectionString="" />
</connectionStrings>

Exception while deploying ASP.NET Website after Using EF

I have two projects, one containing WS which access to the DB and the other one is front-end.
The two projects are deployed on seperate servers.
Before Using EF and linq for accessing the DB in the WS project, everything was working fine, but after that I got and exception saying "the underlying provider failed on open".
Please ca you help me with that. Thank you in advance.
Here is my ConnectionString (WS Project):
<connectionStrings>
-->
<add name="ConString1" connectionString="Data Source=#address,1433;Initial Catalog = MpCarteCoBrandee;MultipleActiveResultSets=True;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
<!--<add name="ConString" connectionString="Data Source=AOUS-PC;Initial Catalog=TestMobilePayment;Integrated Security=SSPI" providerName="System.Data.SqlClient" />-->
<add name="MobilePaymentEntities" connectionString="metadata=res://*/MobilePayment.csdl|res://*/MobilePayment.ssdl|res://*/MobilePayment.msl;provider=System.Data.SqlClient;provider connection string="data source=#address,1433;initial catalog=MobilePayment;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

MVC Connection Strings/LocalDb

Fairly new to MVC so this probably seems like a fairly newbie question.
I've been developing my application using a SQLExpress instance/LocalDb, I'm now ready to deploy my site to production, so my question is how do I configure my web.config file for this environment?
My database has been created in production, I'm just struggling with establishing the connection strings.
I'm using a host that I think does not support LocalDB (GearHost), but sources seem to suggest this is possible (even though I've not found any decent examples).
My current development connection strings are below.
Thanks
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MyApp-20160204160648;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MyApp-20160204160648.mdf" />
<add name="MyEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=MyPC\SQLEXPRESS;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I have a MVC project.I use two conectionString as following
<add name="matematikEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=MYSERVERNAMEONHOST;user id=MYUSERID;password=MYPASSWORD;persistsecurityinfo=True;database=MYDBNAME"" providerName="System.Data.EntityClient" />
<add name="matematikEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=MYPASSWORD;persistsecurityinfo=True;database=MYDBNAME"" providerName="System.Data.EntityClient" />
When i publish the project,i comment first one and second is active,when i work on my PC i comment second and first one is active.This works.

ldap authentication using ActiveDirectyoryMembershipProvider on GC port fails in MVC2 application

I am developing an MVC2 application using C# ASP.NET.
In my application I am using ActiveDirectoryMembershipProvider for user authentication. Below is the snippet from my web.config file.
If I use the global catalog port 3268 in my connection string I get the error "LDAP connections on GC port are not supported against Active Directory". I did google on this error message and was unable to find an appropriate solution. Many people have suggested using port 389, some have suggested code changes. But I want to be able to use the GC port to allow users connected to different forests, because it is more cleaner.
Some observations:
The same connection string(with port 3268) is working perfectly for other applications in my company i.
When I change my connection string to point to port 389 it works perfectly i.e people who belong to the local domain are able to log in. However people from another domain cant.
I put breakpoints in my AcconuntModel and AccountController. With connection string pointing to port 3268,Membership.Provider threw "ConfigurationErrorsException".
It would be very helpful if someone can help me resolve this issue.
web.config:
<add name="ADConnectionString" connectionString="LDAP://myADServer.abc.ad:389/DC=abc,DC=ad" />
<membership defaultProvider="MyADMembershipProvider">
<providers>
<clear />
<add connectionStringName="ADConnectionString" maxInvalidPasswordAttempts="1000" connectionUsername="ldapuser#abc.ad" connectionPassword="password" connectionProtection="None" enableSearchMethods="True" name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.5.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d" connectionStringName="MySqlMembershipConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true" />
</providers>
</membership>
<!-- Added for custom provider -->
<roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="DDMS_Custom_RoleProvider">
<providers>
<clear />
<add applicationName="/" connectionStringName="ddms_dataEntities2" name="DDMS_Custom_RoleProvider" type="DDMS_sourcecode.Utilities.DDMS_Custom_RoleProvider, DDMS_sourcecode" />
<add connectionStringName="ApplicationServices" applicationName="/" autogenerateschema="true" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.5.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d" />
</providers>
</roleManager>
If it is Global Catalog that you need to search, why dont you try it this way
using (DirectoryEntry searchRoot = new DirectoryEntry("GC://DC=yourdomain,DC=com"))
using (DirectorySearcher ds = new DirectorySearcher(searchRoot))
{
ds.Filter = "(sAMAccountName=userID1)";
ds.SearchScope = SearchScope.Subtree;
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
{
uxFred.Content = sr.Path;
}
}
}

Web.config Transform

I have a config that has multiple connection strings. They all point to the same database server. Is there a way to replace a portion of the web.config, i.e.
<connectionStrings>
<add name="Conn1" connectionString="...DataSource=server1;Initial Catalog=DBName..." />
<add name="Conn2" connectionString="...DataSource=server1;Initial Catalog=DBName2..." />
</connectionStrings>
I want to change server1 with server 2. I could do this...
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="Conn1" connectionString="...DataSource=server2;Initial Catalog=DBName..." />
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="Conn2" connectionString="...DataSource=server2;Initial Catalog=DBName..." />
but wanted to see if there was a more all-inclusive way.
According the msdn documentation of web.config transformation there is no possibility for this kind of transformation. You can only do Replace, Insert, InsertBefore, InsertAfter, Remove, RemoveAll, RemoveAttributes and SetAttributes transformations.