Visual Studio 2013 not creating database when I select the authentication option - c#

I tried this on two different computers but get the same issue.
I am using the latest and greatest visual studio 2013.
I create a new project (of type Web->Asp.Net application)
Choose a template type of MVC or Web API (have same issue whatever type of template I select).
Then I change the authentication type to use individual.
The project with all the authentication code is created.
Web.config has the connection string set for a .mdf file.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20131031102303.mdf;Initial Catalog=aspnet-WebApplication1-20131031102303;Integrated Security=True" providerName="System.Data.SqlClient" />
But the mdf file is missing in the app data folder. I searched the whole computer for the mdf file, but it is not created anywhere.
As a result testing my sign in and register modules using a browser gives me the Yellow Screen Of Death with the db connection being the issue.
What am I missing here?

It should be in
C:\Users\[*yourusername*]\Documents\Visual Studio 2013\Projects\WebApplication2\App_Data

This is not a real answer to my question as to why this is happening. But here is the workaround I did to make it happen. I downloaded one of their sample projects which did have the mdf file in the app_data folder. Then I got the table schema from that mdf file and created those tables in my SQL Server database. Then I changed my connection string to point to my SQL Server database. My authentication pages worked after that with this new database. But what a pain to go through.

Related

Attempt to attach an auto-named database when installing my app in another pc

I recently finished building this C# Winforms app that uses a localDB connection and when installing it on another PC, I get the error as shown in the title, even though I included the SQL Server Express localDB in the prerequisites folder.
I tried all kinds of solutions like changing the method of how to build the setup file (using Advanced Installer), but it seems that the problem is always related to the constant AttachDbFilename attribute of the connection string that's not changing according to where the database is newly installed.
Here's how the connection string is defined in the App.config file:
<connectionStrings>
<add name="client"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Surface\source\repos\VisaTurbo\VisaTurbo\Client.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Please I've been stuck with this problem for 3 days now and the due date to submit the application have already been reached.
Thanks in advance
You can by example check the database file exist in %userProfile%\DBName.mdf and create a new one with https://github.com/martincostello/sqllocaldb.
But this make the connectionstrings parameters obsolete :)
You can also generate a new one with SqlConnectionStringBuilder
But if the user move the database file this will reset the application each time.
That's why in general the database in on a server, not locally stored on the user's machine.

Database creation issue after running ASP.NET MVC project

I have a propblem related to the first run of an ASP.NET MVC application containing a database.
I was forced to install a new Windows and migrate my ASP.NET MVC project to it (previously I put it on the Github respository).
In the new installation of the system - I launched VisualStudio, logged into Github and downloaded the project from the repository. However, when I try to run, I get the error:
System.Data.SqlClient.SqlException: 'Directory lookup for the file .... / AppName.mdf "failed with the operating system error 2.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. '
The application previously used a local database. This is what connection string looks like:
<add name="AppNameContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=AppName;Integrated Security=SSPI; AttachDBFilename=|DataDirectory|\AppName.mdf" providerName="System.Data.SqlClient" />
Did I skip any step in configuring new visual studio and don't want to create a new database?
Your application is missing the App_Data folder. Right click on your project, select Add, then Add ASP.Net Folder and choose the App_Data folder.

database file not showing in app_data in asp.net mvc4 tutorial using visual studios 2010

I'm doing this tutorial on ASP.NET: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 and I reached a stage in which I need to work with a database.
Since I'm using Windows XP, LocalDB is not an option, so I configured SQL Server Express instead.
The app is working, but I can't seem to see the MovieDBContext.mdf file in the App_Data folder.
I tried refreshing, building, running, nothing helps.
The only thing in that folder is ASPNETDB.mdf. Does this file contain what I'm looking for?
I opened it and it showed a bunch of tables related to users of the app.
My problem comes when it's time to add new fields to the movie class and coordinate it with the database, meaning I have to turn on migration.
Here are the instructions for migration:
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table
Sadly I cannot delete the database files according to this tutorial since I don't have access to the files.
Is there a way to see the .mdf files?
my connection string is:
<add name="MovieDBContext"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Drivers;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"
/>
In the order they come in your question
The only thing in that folder is ASPNETDB.mdf. Does this file contain what I'm looking for?
Probably yes, it actually depends on the name you gave to the file when it was created.
Your Connection String
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Movies.mdf;
It looks for a file named Movies.mdf in the App_Data folder whereas your file is names ASPNETDB.mdf, either rename the file to Movies.mdf or change the connection string
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;

Unable to find where my database file and connection string is located?

i downloaded a demo application from http://code.msdn.microsoft.com/Authorization-based-aa2c0185/view/SourceCode
I run it on my Visual Studio and all worked fine. There is a database ASPNETDB.MDF in its App_Data folder which is used to store the user information or retrieve information for login purpose.
Now what I want is to change this database with another database in my SQL Server.
For that there can be two ways :
Locate the connection string etc. for ASPNETDB and change them with my own database.
or add this ASPNETDB file to SQL Server by attaching. But its showing error while attaching it.
Also if I exclude App_Data folder from project...Then even it works...
Where can find connection string for DB? I want to change the DB with mine own ?
Please Help
Thanks
It's using default connection string from machine.config:
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
Go to the Web.debug.config file. There you will find comments noting how to wire up your config file. This will use config transforms so that when you build in debug mode, it will change your config file to override the machine defaults (which is what it is currently using). Just follow the comments and you should be good :)

Where is the SQL Server Compact file?

I have an ASP.NET MVC project that uses a SQL Server Compact database. I have the following connection string for my FoobarContext:
<add name="FoobarContext"
connectionString="Data Source=|DataDirectory|Foobar.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
I fired up the project and it appears to persist data as expected. However, I can't find a file named 'Foobar.sdf' anywhere. What am I missing?
Update:
It wasn't taking my connection string. Setting a breakpoint and inspecting the context, I found its ConnectionString was actually the following:
Data Source=.\\SQLEXPRESS;Initial Catalog=MvcApplication3.Infrastructure.Data.FoobarContext;Integrated Security=True;MultipleActiveResultSets=True
Mystery solved.
It definitely should be ~/App_Data by default, but you can try running AppDomain.CurrentDomain.GetData("DataDirectory") to see where ASP.Net thinks the directory exists.
If this reveals nothing of interest, you may want to make sure your windows explorer is set to show hidden files, just in case that's why you don't see the file.
It should be in a folder called App_Data off the root of your MVC project.
you should be stingy on the app folder in your project, the database file you'll find inside.
Regards

Categories