0

I am new to ASP.net MVC. In my MVC application I wanted to have default login functions. Already I have connection string like this for my entity framework connection to application,

<add name="TestDB2Entities" connectionString="metadata=res://*/EntittyModel.SchoolDBModel.csdl|res://*/EntittyModel.SchoolDBModel.ssdl|res://*/EntittyModel.SchoolDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PRAGEETH-PC;initial catalog=TestDB2;user id=sa;password=sa123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Using that connection string I try to use the available function of default pre implemented login functions. I could not use that and show me following error.

“Unable to find the requested .Net Framework Data Provider. It may not be installed.”

Then I try to create a new connection string as follow and then it worked fine,

<add name="TestDB2Entities1"    connectionString="data source=PRAGEETH-PC;initial catalog=TestDB2;uid=sa;pwd=sa123;integrated security=sspi" providerName="System.Data.SqlClient" />

But I need to have only one connection string to suit for both scenarios. Is it possible to have one connection string instead of having two connection strings?Or is it ok to have multiple connection string in my application?

Prageeth godage
  • 4,054
  • 3
  • 29
  • 45

1 Answers1

0

Prageeth,

Assuming you mean the default implementation from the MVC 4 Internet Application template in Visual Sutdio 2012, then you can (and should) have a single connection string. In the template the only one initially is in InitializeSimpleMembershipAttribute, but you will need to add more (see the footnote)

All you need to do is set the connection string name in your UsersContext class to that of your own. Do the same in the InitializeSimpleMembershipAttribute class, and also in any calls to WebSecurity.InitializeDatabaseConnection

If you are using code-first (which, by the way, is the simplest approach when you first use SimpleMembership) you can also:

  • move UserProfile from UsersContext into your own context, and delete UsersContext
  • change the references to UsersContext in AccountController and InitializeSimpleMembershipAttribute to your own context

Footnote

For more information about what SimpleMembership is, and how it works, see my answer to the question How do I use my own database with SimpleMembership and WebSecurity? What is MVC4 security all about?, and for the simplest way to use InitializeSimpleMembership, see my answer to this question

Community
  • 1
  • 1
Andy Brown
  • 18,961
  • 3
  • 52
  • 62