I am trying to use the last connectionString with name sqlConString.
This is my connection string:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-saroh-20170305155508;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-saroh-20170305155508.mdf" />
<add name="crowdfundingEntities4" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="userdataEntities6" connectionString="metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\userdata.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="sqlConString" connectionString="DataSource=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework""/>
</connectionStrings>
I think your problem is connection string Data Source has a space between the word but your setting is DataSource
so try
<add name="sqlConString" connectionString="Data Source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework""/>
If that does not solve your problem, then try:
provide a providerName
if you are using normal ado .net then it should be providerName="System.Data.SqlClient" or
if using entity framework need to addproviderName="System.Data.EntityClient" with adding metadata part in connection string (refer to your userdataEntities6)
if you are using entity framework, a part from adding providerName and modifying connectionString to include metadata also try change " to '
more info about this, check out https://blogs.msdn.microsoft.com/rickandy/2008/12/09/explicit-connection-string-for-ef/
Related
I see that we can use HttpContext.Current.IsDebuggingEnabled in controllers to check if debug=true is enabled in web.config. How can I check the same in startup.auth? I need to set different app Ids for my local and production environments for fb authentication using this condition. Please suggest if there is a better way to do this.
I would recommend creating a web.config entry for whatever dynamic data you need to set and then use web.config transforms to change the data depending on environment. This is very commonly used with connection strings to set different source databases depending on what environment youre in (local vs test vs prod).
See the example below:
local Web.config:
<connectionStrings>
<add name="myConnection" connectionString="Data Source=localhost;Initial Catalog=myDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Web.Debug.Config:
<connectionStrings>
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="myConnection" connectionString="Data Source=myTestSqlServer;Initial Catalog=myTestDb;User Id=myTestUserId;Password=myTestPassword;" providerName="System.Data.SqlClient" />
</connectionStrings>
Web.Release.Config:
<connectionStrings>
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="myConnection" connectionString="Data Source=myProdSqlServer;Initial Catalog=myProdDb;User Id=myProdUserName;Password=myProdPassword;" providerName="System.Data.SqlClient" />
</connectionStrings>
I am new to Castle.Windsor container. I need to access two databases and hence need two connection strings. I have added the details in the web.config file, but I'm getting an error telling the latest connection string is not registered with the container. How to register two connection strings?
Edit: from comment.
<?xml version="1.0" encoding="UTF-8"?>
<connectionStrings>
<add name="XXDB" connectionString="Data Source=XX;Integrated Security=True;Initial Catalog=XX;" providerName="System.Data.SqlClient" />
<add name="XXLogDB" connectionString="Data Source=XX;Integrated Security=True;Initial Catalog=XXLog;" providerName="System.Data.SqlClient" />
</connectionStrings>
This is the connection string in web.config .Have a conenctionstringInstaller which implements IWindsorInstaller where the first connection string is registered... When am adding the second connection string, how can i register it?
Hy!
I'm new to ASP.NET MVC 5. I try to change the default database name. But I don't know how. My goal is to have only one database for the whole application.
My actual working Web.Config:
<connectionStrings>
<add name="DefaultConnection" connectionString="DataSource=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-SqlTest-20131122100021.mdf;Initial Catalog=aspnet-SqlTest-20131122100021;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
This Web.Config file should look like this and should work ^^ (actual I get a error that the database could not be created and the physical name may be incorrect)
<connectionStrings>
<add name="DefaultConnection" connectionString="DataSource=(LocalDb)\v11.0;AttachDbFilename=Example.mdf;Initial Catalog=Example;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Thanks for help :)
You need to add |DataDirectory|\ before Example.mdf, like below:
<connectionStrings>
<add name="DefaultConnection"
connectionString="DataSource=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Example.mdf;Initial Catalog=Example;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I have an MVC5 app that's using EF. I would like to add ASP.NET Identity and I've noticed that the connection string for ASP.NET identity is using "DefaultConnection". What Do I need to do so that ASP.NET Identity tables are created in my already existing db (source=DILS-S1301;initial catalog=MVC5;) as specified in MVC5Entities and NOT DefaultConnection => (LocalDb)\v11.0??
thanks
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MySuperAwesomeMVCApp-20131105011429.mdf;Initial Catalog=aspnet-MySuperAwesomeMVCApp-20131105011429;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVC5Entities" connectionString="metadata=res://*/Models.Mvc5Model.csdl|res://*/Models.Mvc5Model.ssdl|res://*/Models.Mvc5Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I tried modifying "DefaultConnection" like so:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=DILS-S1301;AttachDbFilename=|DataDirectory|\MVC5.mdf;Initial Catalog=MVC5;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVC5Entities" connectionString="metadata=res://*/Models.Mvc5Model.csdl|res://*/Models.Mvc5Model.ssdl|res://*/Models.Mvc5Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
but now i get an error:
Database 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MVC5.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\Users\blah\Documents\Visual Studio 2013\Projects\MySuperAwesomeMVCApp\MySuperAwesomeMVCApp\App_Data\MVC5.mdf' as database 'MVC5'.
The actual question shall be "How do I setup ASP.NET Identity to use my own connection string?"
If above is the correct summary of your question, below is the answer.
ASP.NET Identity uses EntityFramework for database related tasks. So you can use following option as suitable.
Option 1: EntityFramework's default connection string can be setup using following code snippet in web.config
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Option 2: Programatically, you can also pass ConnectionString name to the DbContext's constructor. like new ApplicationDbContext(MyConnectionString)
Actually all you have to do is change the DefaultConnection connectionString to be your desired connection string. If you used the normal settings for a new MVC 5 project, and the identity tables do not exist in the new DB they will be created there automatically.
You do not have to edit the portion of the connection string and you do not have to edit the DbContext constructor unless you want to change the conntectionString name and are not OK with replacing the default connection string.
If you are OK with replacing the default connection string, you should be able to just replace it... this worked for me.
I found this article helpful as well:
http://www.typecastexception.com/post/2013/10/27/Configuring-Db-Connection-and-Code-First-Migration-for-Identity-Accounts-in-ASPNET-MVC-5-and-Visual-Studio-2013.aspx
I am trying to use SimpleMembership in my MVC 3 application. However I get the following error:
System.ArgumentException was unhandled
by user code. Unable to find the
requested .Net Framework Data
Provider. It may not be installed.
I'm using EF and the framework is obviously there since my app works perfect without the SimpleMembership API
Here is the Set Up in the Web config file:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="SeniorProjectModelContainer" connectionString="metadata=res://*/Models.SeniorProjectModel.csdl|res://*/Models.SeniorProjectModel.ssdl|res://*/Models.SeniorProjectModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=GOGOTOPPY;Initial Catalog=SPMT;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
And heres how it looks in the in the Membership file in the App_Start folder:
WebSecurity.InitializeDatabaseConnection(connectionStringName: "SeniorProjectModelContainer", userTableName: "Users", userIdColumn: "UserId", userNameColumn: "UserName", autoCreateTables: true);
Any help would be greatly appreciated!
Update:
The quick work around was to take the metadata part out of the connection string and change the provider name to the SqlClient so it looks similar to this:
<connectionStrings>
<add name="Membership" connectionString="Data Source=serverName;Database=datebaseName;User ID=idName;Password=password;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Is there any downside of the connection string looking like this?
Not sure how you installed simplemembership but try doing it the nuget way for example,
http://www.nuget.org/List/Packages/SimpleMembership.Mvc3