SimpleMembership API connectionStringName error - asp.net-mvc

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

Related

my website doesn't retrieve data from database

I have an ASP.NET MVC web application that communicate with sql server with entity framework.
Now i want to upload my website in a server. I've created database
in that server and restore my local database backup in it then i published my application in filesystem and upload it in server.
My problem is connection string in web.configi know that in connection string we should define data source , initial catalog , user id and password and my connection string is like this :
<add name="Bestshooter1Entities" connectionString="metadata=res://*/Models.DomainModel.Model.csdl|res://*/Models.DomainModel.Model.ssdl|res://*/Models.DomainModel.Model.msl;connection string="Data Source=./MSSQLSERVER2014;Initial Catalog=bestshoo_Database;User Id=bestshoo_DatabaseAdmin;Password=******;Persist Security Info=True;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" />
But it still does not work, what is wrong?
The password of your connection string is ***** please replace it with original password.
Some servers allow you to deploy your database on server and provide connection string to use in your application.
Can you please try with Provider Name:
<connectionStrings>
<add name="MyDbContext" connectionString="data source=.\sqlexpress;initial catalog=YourDbName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient"/>
</connectionStrings>
You just add ProviderName to tag <add />.
<add name="MyDbContext" connectionString="data source=.\sqlexpress;initial catalog=YourDbName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient"/>

ASP.NET Web Site Administration Tool database connection error

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help enter code herein diagnosing the problem: Unable to connect to SQL Server database.
here my connection string in web.config
<connectionStrings>
<add name="MusicStoreEntities" connectionString="Data Source=.;Initial Catalog=MusicStore;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
user localhost like 127.0.0.1 it's should be work
<connectionStrings>
<add name="MusicStoreEntities" connectionString="Data Source=127.0.0.1;Initial Catalog=MusicStore;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
set Data Source= your computer name instead of .

How do I setup ASP.NET Identity to use my own connection string?

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

Switching from SQL Server Express to SDF database

I've created an mvc project with following connection string (which is a default):
<add name="TestDb"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
I would like to switch from SQL Server Express to one of the file databases, so that I can store my db in same repository. How can I do this (steps/connection string) ?
I'm using MVC code first approach. Thank you.
Install the the EntityFramework.SQLServerCompact NuGet package.
Change your connection string to this:
<add name="TestDb"
providerName="System.Data.SqlServerCe.4.0"
connectionString=
"Data Source=|DataDirectory|\aspnetdb.sdf" />
With Code First, you typically use the context class name as your connection string name.

Learning MVC3, connection string

I'm learning MVC3 by covering the famous MusicStore tutorial http://mvcmusicstore.codeplex.com/
The connection string used for EF code first is :
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
I would like to use my localhost SQL Server database (windows authentication) instead. What would be the connection string for it to keep working correctly ? Thanks,
Assuming your DB name is MusicStore:
ConnectionString="Data Source=(local); Initial Catalog=MusicStore; Integrated Security=True;"
Provider="System.Data.SqlClient"
Here:
<add name="MusicStoreEntities" connectionString="DATA SOURCE =(Your Server Name); INITIAL CATALOG =MusicStore;Integrated Security=True;" providerName="System.Data.SqlClient"/>
and have a look on
Connection strings for SQL Server 2008
Regards

Resources