issue while connecting to local database for MVC3 + EF app - asp.net-mvc

I am new to implementing an application on MVC3 + EntityFramework. Can somebody suggest as what approach to apply to access my tables and views from my existing local database (Sql server 2008). I could see some default files created under App_data folder which i dont want.
Cheers,
Chris

You could change the connection string in your web.config to point to your real SQL database:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient" />
</connectionStrings>

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.

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>

How to modify the internet application for mvc projcect in Visual Studio 2012 code and connect with database?

I am beginner in ASP.NET MVC. I have been trying to create a web application in ASP.NET MVC 4 by using Visual Studio 2012. I started with internet application and open with default template that has registration, login, home etc pages. I have tried to modify the code available for the registration form as I want and connect with SQL Server database, but it does not work and also only connected with local database it is not connected with my database table I have created in SQL Server. What will I do? Thank you for your help
Have you changed your default connection string in your web.config to point your sql server?
The default connection string will be like this
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-yourproj-timestamp;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-yourproj-timestamp.mdf" providerName="System.Data.SqlClient" />
In your case you should have changed as follows,
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=aspnet-yourproj-timestamp;User Id = xxx;Password = xxxxxx" providerName="System.Data.SqlClient" />

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.

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