where is aspnetdb.mdf in mvc3 default sample program? - asp.net-mvc

In the default sample appication in mvc3, Where do the details we fill in registration form gets stored?
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I did not find any aspnetdb.mdf file in app_data folder.

You need to click the 'show all files' option as it is hidden IIRC.

Related

ASP.NET MVC : web.config connection string for multiple developers

I have been looking and reading, and I could not find this solution yet.
I have a small ASP.NET MVC project I am working with two other developers, we have the same settings, just the computer name is different.
So, our connection strings section in web.config looks something like this:
<!-- Hugo
<add name="DefaultConnection" connectionString="data source=DEKSTOP123\DATABASE;..."/>
<add name="OtherConnection" connectionString="metadata=res:...;data source=DESKTOP123\DATABASE;..."/>
-->
<!-- Paco -->
<add name="DefaultConnection" connectionString="data source=DEKSTOP456\DATABASE;..."/>
<add name="OtherConnection" connectionString="metadata=res:...;data source=DESKTOP456\DATABASE;..."/>
<!-- Luis
<add name="DefaultConnection" connectionString="data source=DEKSTOP789\DATABASE;..."/>
<add name="OtherConnection" connectionString="metadata=res:...;data source=DESKTOP789\DATABASE;..."/>
-->
We just comment and uncomment whatever connections is ours, but it's messy. Is there a better solution for this?

Is there a way to check debug=true in startup.auth in ASP.NET MVC

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>

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 .

ASP.NET MVC 5 change database name

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>

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

Resources