Publishing the project to Plesk Hosting - c#

I have four projects in one solution
RapporAMS.Data (Contains the connection string and database access queries and entity framework installed, it also have connection string in app.config file same that of web.config in forth project)
RapporAMS.Service (Act as an interface between RapporAMS.Data and RapporAMS.MVC )
RapporAMS.Entities (Contains all the Entities and view models used in the solutions i.e business objects)
RapporAMS.MVC (MVC project front end of the application also have connection string in web.config and entity framework installed)
I have created the database in Plesk named "esssospa_AmsDB" with username and password. Then I used "import dump" to import .bak file. Now, it is showing file size and the total number of tables in the database.
I am not sure about database has been attached to esssospa_AmsDB or not
After that. I winziped only RapporAMS.MVC project and uploaded it to the httpdocs directory on the server.
Then I changed the connection string in web.config don't know how to change the connection string in app.config of RapporAMS.Data. This may be the issue of the error.
Problem 1: Database esssospa_AmsDB is not showing up in my SQL EXPRESS 2014 when I logged in using the credentials.
Problem 2: Having 500-Internal Error when I access the website, further screenshot is attached. click # Database on Server

Related

C# MVC local database creation while App Start

When the app runs for the first time with a new connection string name it creates the Local Database files in the App_DATA folder, but it doesn't recreate it for the 2nd time if the database files missing in the App_DATA folder... Will have to change the database name given in the connectionstring. Why?
How to solve this problem?
Where it stores the state that the database has been created for the first time...
How it does the comparison/check to confirm whether the database has been created during an app start previously?
Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebDemo-20210104031025.mdf;Initial Catalog=aspnet-WebDemo-20210104031025;Integrated Security=True"
it knows the database "aspnet-WebDemo-20210104031025" has been created and looks for it in the App_Data folder. doesn't re-create it for the 2nd time when it is not available in the folder
** Didn't use code to create custom tables, just only the basic template comes with Visual Studio 2017 MVC web application including authentication(not azure- just user creation with email and so on....)

Why the message "No databases are selected to publish" is shown when trying to publish a web?

I created an application on my local machine using
1) MVC
2) Entity Framework
3) LocalDB
When I go through the publishing wizard it tells me that "No databases are selected to publish"
Why is it not detecting I have a database to publish, even though I entered the connection string manually(from web.config)?
I followed the guide in the link:
https://msdn.microsoft.com/en-us/library/dd465337(v=vs.110).aspx in "Configuring Databases in the Settings Tab" section.
Still, when I enter the connection string of the DB in the destination remote connection combobox under "Databases" title and try to publish- The mentioned message is displayed.
Do you have any idea what the problem is?
Thanks
Assuming this is an MDF file in App_Data (couldn't tell exactly from the question) make sure:
your connection string includes "AttachDBFilename=|DataDirectory|\XXX.mdf"
your MDF file is part of your solution under App_Data
the .mdf file is configured as "Content" for the Build Action.
Also In your publish profile, ensure that "Exclude files from the App_Data folder" is not checked under File Publish Options.
This all worked for me using EF6 code first. You should not need to specify a connection string in the publish page unless you want to change it from your web.config.

How to deploy mvc application to an hoster

I am bulding an application with MVC.
Ont thing I don't understand, it's how to deploy to an hoster when building is finished and how to link database on the hoster.
Now I create the application and the database was automaticly create on first run of the application. I have create a dbcontext class, a model class (with entities) and a controller with actions.
The database was created but also a file database, I think not in sql server express.
No connection string was added in web.config, the database is in the app_data folder.
My questions are :
is that the database will be shipped within App_Data and the application will work without any further configuration in sql server on the hoster ?
is that the database will be created automatically at the first run on the hoster ?
If no, How to create a script SQL which will create the database and will be needed connection string in web.config
tks for help
is that the database will be shipped within App_Data and the
application will work without any further configuration in sql server
on the hoster ?
The answer is no because by default in web.config you have (LocalDb) which is a version of SQL Server that comes with Visual Studio. To make it work you have to install on server this version of SQL Server.
is that the database will be created automatically at the first run on the hoster ?
The database can be create automatically if you specify that connectionString to be over a version of SQL Server.
Note: If you use migration you can check at Publish Execute Code First Migrations
If you can install (LocalDB) on the host server, than you can leave the connectionString as it is.
If you use other versione of SQL Server you change the connectionString to be like below, the values from Data Source, User ID and Password must be changed to match your server connection
<add name="DefaultConnection"
connectionString="Data Source=ServerAddress;Initial Catalog=DatabaseName;Integrated Security=False;User ID=UserName; Password=UserPassword"
providerName="System.Data.SqlClient" />

Adding new Service-based database to C# project in Visual Studio 2013

Lately i was building C# windows forms application with service-based database.
I was forced to make few changes to make it work, but it's still not working as it should.
I'am doing this at start:
1. Add Service-based database to project
2. Create Tables
3. Add Entity framework 6.1.2 Model to project
This creates seccond database file in Project and in Data Connection. Now if i want to show any data, I must create dgv and dataSet pointing at this newly created .mdf file. Also i need to change Copy to Output Directory to Copy if newer. Now I can see my data, but i only see empty table in Data Connection in Server Explorer. Also if I open it and refresh, all data in my application are gone.
Is there any tutorial, or something about How to add Service-based database and connect to this file using entity framework, wihout coppying it to output directory?
If someone need a solution for this case, there is one:
Create database in any program (could be visual studio)
Copy it to /bin/debug/
Put bin folder to your solution in Visual Studio
Select database and make Copy to Output - Do not copy
Edit connection string in entity framework to
attachdbfilename=|DataDirectory|\file.mdf;
Database should now appear in Server Explorer in VS. You can now remove all newly created databases (leave only this one you copy to bin/debug/)
Now you will see correct database in Data Connections, and your program will update this one. You can easily coppy your solution to any other location, and connections will not be messed up.
Btw, I think this is entity framework error or DataDirectory should point to Solution folder, not bin/debug. I know we can change DataDirectory pointing...

.NET including class library database (and other resources) with windows app deployment

I have a class library that attaches itself a tiny SQL Server database that resides in its Data Directory. When i'm using this class library with another windows application i see that once i compile my code, the database files get copied to the bin folder of my windows app project. However when i publish the windows app,install, and run it, i get the error 'An attempt to attach an auto-named database for file C:\Documents and Settings\User\Local Settings\Apps\2.0\Data..\DB.mdf failed.' Obviously this folder doesn't have the mdf files.
I guess this won't be a problem if i just add the database files to my windows application project. But surely there's a better way?
You could include an SQL script for creating the database into your "installation/run first time routine".
I guess that you've already stated that having a form of SQL Server is an installtion prerequisite.
For the data files I would recommend that you use a variable connection string for accessing your database. That way you can change the installation routine to include asking the user where they wish to have the data files installed and save that as part of your connection string to the app.config file.
Conversely you could also use the users selection of where to install the app to override the relative path stored for the database within your code (using the same connection string variable as mentioned above).

Categories