Connection string connects to wrong database in ASP.NET MVC - 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

Related

Connection string problem when deploying ASP.NET MVC website to PLESK

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).

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 project database cant find

I'm a beginner in MVC application development. I'm just trying to make a MVC application getting help from internet. That was a simple example and working properly. The article is said the database is in app_data folder. But actually there is no any database in that folder. Then I just tried to find the physical database location using the connection string.
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-ePhoneBook-20140322204146;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
as the above connection string (I just not write down this and it is auto generated code in web.config file), the database name is "aspnet-ePhoneBook-20140322204146". Then I checked weather this DB available in physical location of the sql databases. My all other databases (My old projects' databases) are in that folder. But couldn’t find this database. then I tried with folder searching option in windows 7. There is no any database with that name. The wonder is my application run properly. Data saved properly. SQL management studio also not showing the database.
My question is, How to find the physical location of the database and why is this database not showing in SQL management studio.
The issue is you're pointing to SQL server, and ,definitely, not to separate attached database file.
your connection string should look like this:
<connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ePhoneBook-20140322204146;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ePhoneBook-20140322204146.mdf" />
where |DataDirectory| - is actually App_Data folder in terms of ASP.NET.

What am I doing wrong with my deployed connection string?

I’m having a problem with my connection string after deploying. My site, www.coopersystems.net, is hosted by Godaddy. I’m using Visual Web Developer Express 2012 using E-Code First. Godaddy gave me the following connection string information:
Data Source=MyDatabaseName.db.10000000.hostedresource.com; Initial Catalog=MyDatabaseName; User ID=MyDatabaseName; Password='MyDatabasePassword';
I then used this info to change my connection string to the following:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=MyDatabaseName.db. 10000000.hostedresource.com; Initial Catalog = MyDatabaseName; User ID=MyDatabaseName; Password=’MyDayabasePassword’;Integrated Security=True" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="ApplicationServices" connectionString="Data Source=MyDatabaseName.db. 10000000.hostedresource.com; Initial Catalog = MyDatabaseName; User ID=MyDatabaseName; Password='MyDatabasePassword';Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
The default page shows up fine but clicking on the tabs that should load other pages does not work. The page seems to hang for a while then the error page shows with error: “We’re sorry, we’ve hit an unexpected error. Click here it you’d like to go back and try again”.
My first question is:
1: If my connection string is wrong, would my default page still load? I ask this because when I tried changing keyword/value the home page would not load.
2: Is there something other than my connection string that I may be able to check?
3: How can I solve this problem?
Any suggestions or help would be greatly appreciated. I’m going on my second week of trying to get Godaddy to help and using their forums. Nothing has worked yet.
Latest attempts:
So I fixed the password quotes and had godaddy configured the config file to show the error message..
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I assume the server not found to mean that I provided the wrong name for a server on the Web Publish wizard so I’ve been trying different combinations of Server Name, Site Path, and Destination URL.. I got the site deployed with a few combinations of those values but the links still wont work.
Is there a configuration that maybe I should’ve done before using the “Publish” function of Web Developer Express 2012? I am out of ideas and Godaddy can’t help.
After one week of trying I decided to try to connect to the database using IIS 7.5. I can't connect with this either so I guess If I can solve connecting to the site or database with IIS I should be able to solve my other problems. Please help if you can. Thanks.
Try removing the single quotes around the password:
Password=MyDatabasePassword
Turns out that my ISP is blocking port 1433. No mater what I do I can't access the database.

ASPNET authenticate fail with IIS

I have develop MVC Web Application
I use ASP.Net authenticate to implement my login form
The problem is that i cannot deploy it to server.
In the first i use ASPNetDB.mdf which is a file store in AppData forlder
After that I change to store ASPNETDB as a database in SQlServer and also update the connectionstring to new database
In the development environment both of them work well
But when I deploy to IIS, I cannot login, it show me following error :
"Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed."
Here is my connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=.\PHDatabase; Initial Catalog=aspnetdb;User ID=sa;Password=****" />
</connectionStrings>
I try to google a lot but until now, there is no result
Please help me to solve the problem
Regard
Try replacing machine name instead of a "."
Data Source=machinename\PHDatabase; Initial Catalog=aspnetdb;User ID=sa;Password=****
The other possibility is if you are using certain wizards like Linq2Sql etc., they might keep the connection string inside the code. Check for them as well..
In development environment, when you are using Attached Database file from App_Data folder with SQL Express, you should use the following connectionstring
<add name="YourConnectionStringName"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\YourDatabase.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
But, when you testing or deploying with Database on the SQL Server, you should make use of following type of connectionstring
<add name="YourConnectionStringName"
connectionString="Data Source=db.YourhostedResourceName.com;
Initial Catalog=YourDbName;User ID=yourusername;Password='yourpassword';"
providerName="System.Data.SqlClient" />

Resources