Connection string problem when deploying ASP.NET MVC website to PLESK - asp.net-mvc

I'm going through a basic tutorial for ASP.NET MVC based on this Microsoft Help document. The app displays books and authors from a database and allows for CRUD operations on that data. Everything is working fine on my machine when I run locally developing with Visual Studio 2017. But when I try to to deploy to my PLESK hosted website I'm having problems. I recreated (from scratch) a MySQL database designed to exactly replicate the schema of local database and populated it with sample values. When the page loads, I'm getting a long hang and ultimately a 500 error after it tries unsuccessfully to connect to the database.
This is the connection string that is working locally:
<add name="BookServiceContext" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=BookServiceContext-20200803155333; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|BookServiceContext-20200803155333.mdf" providerName="System.Data.SqlClient" />
And here's the connectionStrings part of the remote web.config:
<add name="BookServiceContext" connectionString="Server=###.##.###.##;Database=BookServiceContext;Uid=myPLESKUserIDAssociatedWithDatabase;Pwd=PasswordForTheUser;multipleactiveresultsets=True" providerName="System.Data.SqlClient" />
Perhaps I have the syntax wrong or am missing a setting in PLESK (I was trying to use a sample from ConnectionStrings.com and haven't set up a DB in PLESK before).

Related

In ASP.Net Database First Approach , Why can't i see ASPNet tables (ASPNetRoles, ASPNet users etc)

I have created ASP.NET MVC Web application but I cannot see ASPNet tables created in database.
Tried so far:
I checked in web-config file if choosing the authentication at the time of creation of project makes this difference and and found <authentication mode="None" /> in web-config. So I thought may be because i might have chosen No Authentication in the beginning that is why I dont have those tables in database. Then I have changed manually in web-config file to <authentication mode="Forms" /> to create individual user authentication.
However even after updating the authentication mode to forms it is still not showing ASPNet tables in the database.
I have noticed that ASP.Net Identity tables are created in localDb and I have created my another database with tables for my application. Now I want to see ASPNet Identity tables from local db in my own created database.
In the web-config file i have updated the data source with the data source of other connection string of my database .
<add name="DefaultConnection" connectionString="Data Source=SQLCLUSTER;initial catalog=TimeSheet;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="TimeSheetEntities" connectionString="metadata=res://*/TimeSheet.csdl|res://*/TimeSheet.ssdl|res://*/TimeSheet.msl;provider=System.Data.SqlClient;provider connection string="data source=SQLCLUSTER;initial catalog=TimeSheet;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings> ```
After running the application in debug mode I still can't see the ASPNet tables in my own database.
How can I get those tables?
What did I miss which is cause of this issue?
Any clarification would be much appreciated as I am newbie and learning Authentication and Authorisation at this point.

Connection string connects to wrong database in ASP.NET MVC

I'm trying to develop my first web app. I deployed my app to the server host (SmarterAsp.net) and kept having trouble connecting to my app's database.
I tried connecting to the app database locally (running my app in my Visual Studio with IIS Express) with the smarterasp username and password and it connected to my local database. I even took out the connection string entirely and it still connected to my local database.
I tried connecting to my app database in SSMS to see if I have the wrong user name and password and it worked perfectly fine. I'm at a loss to figure out where I'm going wrong
Here are my connection strings
<add name="TimeSheetDbContext"
connectionString="Data Source=data source.net;Initial Catalog=catalog;User Id=user id;Password=password;MultipleActiveResultSets=True "
providerName="System.Data.SqlClient" />
<add name="DefaultConnectionEntities"
connectionString="metadata=res://*/VerifyCompanyCeo.csdl|res://*/VerifyCompanyCeo.ssdl|res://*/VerifyCompanyCeo.msl;provider=System.Data.SqlClient;provider connection string=';data source=data source;initial catalog=catalog;integrated security=false;User Id=user id;Password=password;MultipleActiveResultSets=True;App=EntityFramework';"
providerName="System.Data.EntityClient" />
Here is my database connection code code in my controllers
private TimeSheetDbContext db = new TimeSheetDbContext();
I tried to clear the Visual Studio cache but that too didn't help. Any help would be greatly appreciated thanks so much

Deployed application doesn't work after changes connectionString MVC ASP.NET

I made application using DataBase First approach with oracle (in this way https://www.youtube.com/watch?v=tk_EDjTzZCE so I used Entity Wizard)
I deployed my application on http://www.smarterasp.net/
Everything works fine.
But I decided to change connectionString in webconfig. Because I wanted to use database from another server. New Database has literaly same structure as old but still doesn't work.
Also I tried to change connectionString before deploy. I compiled the application and when I run - receives an error: ORA-00942: table or view does not exist
If I add database again using Entity Wizard (check youtube link above) then everything works fine. How can avoid this? Maybe my connectionString is wrong?
<connectionStrings>
<add name="DbEntities" connectionString="metadata=res://*/DAL.DbModel.csdl|res://*/DAL.DbModel.ssdl|res://*/DAL.DbModel.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=some-link.com:1521/ORCLBK;PASSWORD=some_password;USER ID=some_login"" providerName="System.Data.EntityClient" />
</connectionStrings>

mvc 4 I've deployed to production server. Now cannot connect to localdb

I finally have a published website. Now I want to continue development so I changed my webconfig back to the previous working localdb connection string.
<add name="HouseContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MVCBSV;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MVCBSV.mdf" providerName="System.Data.SqlClient"/>
and then commented out the connection string to the production server.
<!--<add name="HouseContext" connectionString="Data Source=bstatus2014.db.10188888.hostedresource.com; Initial Catalog=bstatus2014; User ID=bstatus2014; Password=Bstatus!2014;" providerName="System.Data.SqlClient" />-->
But when I run the project, the data that is retrieved is the production data! I've tried clean and then build solution but no effect. Probably related, is that I published to the local IIS following the web deploy suggestions adding an application pool. Also if I use the connection wizard specifying localdb/v11.0 it no longer shows my MVCBSV.mdf db.
Also I was trying to use transforms debug/release to make this change, but have found a post that transforms don't work on debug.
A beginner so explicit answers are a help.
Yea, if you publish to your local IIS then your application is probably tied to that site. Open IIS, find the published site open the folder your published code is in and then look at the Web config it is associated to it. Also try recycling the app pool.
Transforms should only be used when you are publishing to a non-local environment anyway. Beyond that if you publish it might make more sense if you published to a location in your file system.

Which connection string WSAT uses

I create a new ASP.NET MVC project with internet template.
I build the solution.
I open ASP.NET Web Site Administration Tool (WSAT).
I click the security tab
I get this error:
"Unable to connect to SQL Server database."
I am using Visual Studio 2012 and SQLServer Express 2012.
I don't have IIS installed (other then what ships with Visual Studio).
The Connection String from the new project:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication2-20130804051506;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication2-20130804051506.mdf" providerName="System.Data.SqlClient" />
It is worth mentioning that I did not change anything in the web.config after its initial creation and that MVC project seems to be working properly e.g. I am able to register and login and then see that data in the (LocalDb)\v11.0.
I read on other posts that the connection string from machine.config is sometimes used instead of the one from web.config.
I have a two machine.config files, one under C:\Windows\Microsoft.NET\Framework\config\v4.0.30319 and the other under C:\Windows\Microsoft.NET\Framework\CONFIG\v2.0.50727
When is a machine.config's connection string is used instead of my web.config's connection string?
I want to use the (LocalDb)\v11.0 data source, why does WSAT unable to connect to it?
From http://forums.asp.net/t/1483981.aspx/1 :
by default, the membership / role provider uses the "localSQLServer" connection string which is set to point to a local SQL Express database from the root web.config. In most cases, the server do not have SQL express installed and you will get this error.
By clearing the connection strings should reveal those errors.

Resources