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.
Related
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" />
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
"
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" />
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;
}
}
}
Yes, one more question about Provider manifest token. Unfortunately all previous 22 questions was not useful to solve my problem. I developing simple web application using MVC4 + Code First + Sql Express.
Here is my context descendant:
public class MCQContext : DbContext
{
public MCQContext()
: base("name=ApplicationConnection")
{
}
...............
}
And here - part of web.config related to the problem:
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ApplicationConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="name=ApplicationConnection" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
So, as you can see, correct connection string passed to base of context class (I got the same error if I rename connection string to "MCQContext" and do not pass anything to parent context class).
I have no idea how to fix it. This behavior reproduced if I creating absolutely empty MVC4 application, remove all packages (I prefer manually specify required assemblies and do not use NuGet) and fix references (including reference to sqlserver express).
The problem with your connection string here is:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.sdf;
User Instance=true"
providerName="System.Data.SqlClient" />
You're basically defining what "server" you're connecting to - but you're not saying what database inside the file to connect to. Also - the file extension for SQL Server Express database files is .mdf (not .sdf - that's SQL Server Compact Edition) - you need to take that into account, too! (was a typo, according to comment by OP).
You need to define an extra database=.... (or Initial Catalog=.....) in your connection string:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=YourDatabaseName;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Then it should work just fine.
Is it possible to separate ConnectionStrings and mailSettings from web.config?
Devel environment has different IP addresses for connectionstrings and smtp mails because of development and testing. We dont want to do tests and devel using live machines and live IP addresses.
Is it possible?
I found the answer on MSDN:
<configuration>
<connectionStrings configSource="connections.config"/>
</configuration>
With file connections.config containing
<connectionStrings>
<add name="name" connectionString="conn_string" providerName="System.Data.SqlClient" />
<add name="name2" connectionString="conn_string2" providerName="System.Data.SqlClient" />
</connectionStrings>