Can't find my EF code first db - c#

I know that there are some similar topic, but still I haven't found soultion.
I have create a simple ASP.NET MVC app with EF code first. I set no connectionstring, and everything works fine. I can perform CRUD actions and records are updated. But I don't know where my database is.
I am using Microsoft SQL Server Management Studio to connect to server. In Server name field I have tried to put: localhost, ., .\SQLEXPRESS, my Desktop name. These are all answears which I have found searching solutions.
Then in all cases I expand Databases/System Databases and all other Databases, but I can't find mine.
I know, that I can create an empty Database in Management Studio and set connectionstring to this DB (and it works), but I must send app to my teacher, and you know, he want to only click run, without setting up anything.
Have you got any solution?

Looked in yourproject/App_Data? Usually, the DB files are created there

Related

How to store SQL Server Database in my App to deploy it?

I'm very new to App deployment. This is my first one actually.
I developed an app which uses a SQL Server database to store its data. I created the SQL Server database with a script. However, neither the script nor the DB itself are part of the "package" of the app. I simply installed SQL Server Management Studio with the default settings, created a new file starting with
USE [Master]
GO
CREATE DATABASE [Database]
and filled up all the details.
The app works in my machine of course, but when I Published the app and got the .Exe, it doesn't work in any other computer, of course because it's not creating a Database to go with it, and the connection string that it uses for the queries is the one that I gave it from my SQL Server instance.
So, I want to know how to actually include the database (or a way to create it) in the "installation package", and also for the program to dynamically get the necessary connection String to operate on any computer where its installed. Right now, I AM fetching the connection string from App.Config with the ConfigurationManager, but of course, the Connection String in App.config is the one that got added when I added MY instance to the project.
Any sort of guidance would be appreciated. I searched related questions but the only ones relevant had some deprecated methods. It's still not very clear to me how it would get the connection string dynamically if its not going to be the same instance.
On a semi-related matter...I noticed that my app was being executed with just double clicking on "setup.exe". Setup seems to imply that it will only install it and add an executable...it's kind of misleading to execute the app itself from the setup, isn't there another way to change that?

Publishing ASP MVC 5 code-first EF along with it's localdb

I have an ASP MVC 5 application using Code First EF. I am setting up an environment to debug on a remote machine and follow these steps.
The website itself publishes fine, but I'm needing to publish the EF local databases along with it as well, content included. I've been digging around online but have had difficulty finding a step-by-step process for doing this that also allows for EF code first updates to the remote database.
Any help would be appreciated.
As for connection , try modifying the connection string in webConfig. As for the information, I'm not 100% sure on this, but I'd you think you would be able to backup the database and restore on the remote machine.
There is a _migrationHistory table in the database that EF refers to when checking the models against the database, so by restoring the whole database (and the _table as the result ) EF should not lose its state ( you won't need to run Update-Database).
If you publish to a server, you can use different appsettings for development and production using different web.config-files as described here
And for your database:
I pretend you want some content of your database being transferred into the production database in addition to get the right structure of tables too.
In this case, Migrations could do the job:
If you create your database with CodeFirstMigrations you can be sure, that your structure is right, by migrating the database before publishing.
And for the data, you can use a Database-Initializer to get the required data into any database your targeting as long you have enough permission for this.

Issues setting up ASP.net Membership and MySQL database

I'm currently working on a school project which I almost finished. I tested it and it was working fine on my local machine. Then I uploaded it to a webserver to test it and I got an error.
Apparantly you have to configure an external MySQL server and database to get the ASP.net membership system working. (I know it's stupid but I honestly didn't know).
So now I've managed to get a free database (since it's for school purposes it doesn't matter) and I want to save the required information for the membership service in this external database.So now I have to do these three things:
1.Getting to know which columns from the local database I have to insert in the external database (e..g. username: VARCHAR(20) etc.) I need to get this info from my local database...
2 replacing the connectionstring in my web.config file to get it working with my external database.
I searched the web a lot but couldn't find the right thing to do: GETTING TO KNOW THE COLUMNSI read online it was useful to use Microsoft SQL server management. I downloaded it so I could connect to my local (automatically generated) database. I couldn't figure out how to log in. Using my machine name or just a '.' both doesn't work....edit: this is what I mean (picture) what should I do?
REPLACING THE CONNECTIONSTRING
To be honest, I don't understand the connectionstring at all...
If anyone know what to do in these two problems I would really appreciate the help!
Thanks in advance,
Elias
You seemed to ask several questions (above) so I will try to answer enough of them to get you pointed in the right direction.
First, MySQL is not the same as SQL Server. They are different/competing products. From your comments, it sounds like you need to attach a .MDF file which is a "Microsoft Database File". Instead of MySQL, you need to install SQL Express (free). SQL Management Studio will allow you to attach your .MDF file and set up permissions, etc.
Since this is for school, you can use your DB mgr to create a test account with a simple PW. It could be something simple like User: Demo, Pw: D3mooo{ (or whatever you can remember). By default Sql Server only allows you to grant permissions to accounts from your OS. To change that, you can use SSMS, right-click the server, choose Properties, security and change the "Server authentication" to "SQL Server and Windows Authentication mode". Otherwise, you could just grant permission to your IIS server's identity, which is usually some name like [machinename\IUSR] (with square-brackets).
Once that is set, you need to create a "connection string". The easiest way is to create a text file on your desktop and rename it from new text Document.txt to dsn.udl. The file extension is the trick, it must be .udl instead of .txt. If you get it right, the icon will change and you can double-click it and go through the wizard to make/test a connection string. When you are done, you can open the udl file with notepad, and it will contain a working connection string. Copy the connection string into your web.config and things should start working for your membership DB.

asp.net app on IIS can't connect to localdb

I have an asp.net web app running on IIS, and everything is fine, until I try to access the database I get this error:
I have read the 2 parts of the Using LocalDB with Full IIS: 1 Part | 2 Part
I followed the instructions and still get the error, is there a way to check that I have followed the steps correctly?
Is there anything else I can check for that may be causing this error?
Note: I tryed this with asp.net and asp.net core applications, the core one doesn't give any description at all so I am testing this with asp.net. The database that I am using is the one that visual studio provides. If you would like me to provide any further information ill be happy to, I have been stuck with this issue for a while now and can't seem to resolve it.
Turns it's not too complicated, but my inexperience with both IIS and Databases made it confusing. Hopefully this can help someone in the future. There might be some minor steps/tweaks I missed out but that's because the whole solution took a while to setup.
Make sure you have SQL Server actually installed. You can download the 2008 version which I used here. Can be a pain to setup and I actually messed up when installing, here is the vid I watched (I didn't install: Database Engine Services).
Next you want to make sure the IIS identity (IIS APPPOOL\ASP.NET v4.0 in my case) has permission to connect to the Database server. Check the answer here.
Once it has connected to the database server, it need's to be able to connect to a database on the server (I didn't know that a database and a database server are 2 different things). You need to do something simular to Step 2, in SSMS expand the databases folder, and select the database you which to grant access too, there is a security folder in there as well and you want to add the Identity to that folder.
Other useful points:
If your sql configuration manager isn't opening please tell it to, thank you gofr1. This is a very useful tool for checking up on your database connection (as it turns out)
Make sure you setup your connectionString to point to the sql server. Make sure it doesn't connect to the mdf file with AttachDbFilename=|DataDirectory|\your_database_name_here.mdf located in the connectionString.
For asp.net Core read the documentation it is god, as the errors are non-existent once the app is deployed on IIS it will help in dark times. Always check publishOptions.
To further help you understand how the whole process works, thank you to gofr1
read here. Didn't solve the issue but worth a read.
Might include more stuff in here later if I remember I missed anything out.

accessing database

Here is my problem; I have a hosted and published database on godaddy servers. I have also published my website. However, when I tried to use one of visual studio's tools such as chart, or data view or any tool that wants me to specify a data source, I get the
"error 40: could not open a connection to sql server".
In most cases, I have worked around this issue by writing the code instead of using these tools on the ".cs" sections, but now I need to update my database model and I really would prefer not to write that amount of code. The connection string I choose works perfectly, it can update and gather values from database on the published website. But when I Right click on the models section and select "update model from database" the update wizard cannot access the database with the very same connection string. Like I said, this problem occurs on every tool that wants me to select a data source.
Is this a permission issue regarding visual studio or something else?
Thanks in advance.
By default, Go Daddy does not allow access to your database from anything other than your shared hosting account. We allow you direct database access from other locations if you select that option at the time you created the database. If you did not select this option when you created the database you will never be able to connect to it from a location other than your hosting account. If you did not select this option at the time you created the database and need to add that option you will have to create a new database with the option selected.

Categories