Creating Database Model on ASP.NET MVC with MYSQL - c#

I'm using ASP.NET C# with database MYSQL, I follow this step on creating a database model with Entity Data Model Wizard http://www.asp.net/mvc/tutorials/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs. When I run this, it showed error --> Unable to generate the model because of the following exception: 'The provider did not return a ProviderManifestToken string. Access denied for user 'root'#'localhost' (using password: NO).
I already have connection with the same connection string uses on webconfig MySQLMembershp I copied from this How do I setup ASP.NET MVC 2 with MySQL? which is working.
if they have the same connection string uses this should work, but why is not working when I create a database model.

First of all EF model connectionstring and Asp.NET membership connectionstring is different. Secondly you may have to see how EF model works using MySQL database here
Getting MySQL work with Entity Framework 4.0

It seems like you have no password. Have your tried using the password "root"?

Related

I am trying to update a record in a table using Entity Framework Core but I am getting an exception

I am trying to update a record in a table using Entity Framework Core in ASP.NET Core MVC, but I am getting an exception while calling
context.SaveChanges()
saying that record is not there or deleted.
But that record with same id is there in table. I checked it with debugging.
I am suspecting you are referring to the wrong database.
I have encounter this problem before and the problem is that while I created the connection to the database to generate the model, VS let me choose whether to include the .mdf in the solution and change the connection string.
Please double check your connection string is pointing to the right database.

Visual Studio not creating edmx file using Entity Framework 6.1

Im trying to use Entity Framework on my .NET 4.0 Web Site. I already have installed Entity Framework 6.1 and i "Add New" ADO.NET Entity Data Model to my site using a valid connection string , and I select my table. I know this is a valid table with several columns and rows of data. After the creation is finished I am left with only a .cs file with no properties and a new connection string added to the web.config, but there is no .edmx file created. I know the SQL user in the Con String has read/write permissions and this is a valid table. Any clue as to what i may be doing wrong?
Have you tried to change the values of this new connection string with your values?
Take a look of this link and retry..
https://msdn.microsoft.com/en-us/data/jj206878.aspx
PS: I think that you should have created a "Project" and not a "new WebSite" using:
"Folder>New>Project> ASP Web App" in VS
Doing this you have all ready to go (references, EF etc..) then you could even start from a empty virgin model, or EF designer from database where you could easly manage or create entities, relations etc.

Entity Framework code-first filter data on database and read it from EF

I have a C# project with EF code-first approach. The purpose is to do crud operations. My web app will be hosted under IIS under two folders
web app
WCF service
The application will pass user credentials to the WCF service and then to SQL Server database. Code first approach works well in this case.
READ scenario: the data needs to be filtered on the database level, not on application level. So I cannot directly call tables while querying SQL using EF. User will not have read access on the tables but only on views. The SQL views will have responsibility to filter the data and then pass to the service.
The question is how to proceed with EF code first approach in a way that I can leverage the benefits of EF migration s and then map the tables to the SQL views. Can anyone explain how to proceed with this read scenarios and best approach?
Entity Framework doesn't support mapping to Sql views but you can do the following:
Create an entity class that mapping your (sql) view structure.
Add a new empty migration using the add-migration -IgnoreChanges command since you don't want your entities to map to tables.
In this migration you can create (Up method) your Sql view.
It is important to note that you have to indicate the Sql view name in your entity ("view entity?") configuration (mapping) class:
public class FooConfiguration : EntityTypeConfiguration<Foo>
{
public FooConfiguration()
{
ToTable("ViewName");
HasKey(p => p.Id); // You also have to configure a key
}
}
This article from Julie Lerman could be interesting for you: https://msdn.microsoft.com/en-us/magazine/dn519921.aspx

How to get lightswitch table data in mvc controller?

I am new and beginner in light-Switch,
I am doing light-Switch with MVC.
Let me explain my scenario:
First I have created one light switch application. In this app having one project is called [ProjectName].Server
Then I've Connect my SQL database in Light-Switch application. And try CRUD operation via Light-Switch screen and its working fine.
In This server project I've create MVC structure like controller, model and views. using Click Here
Then I've create simple Index view in Home controller and its open successfully.(via open browser from desktop client)
Now i want to get light-Switch table data(records) in my controller via entity Framework or light-Switch data context. suggest me easiest way..
I don't know how to get data in controller using light-switch data context. so I've try with entity framework using DbContext and DbSet.
But i got error:
One or more validation errors were detected during model generation:
LightSwitchApplication.Data.[EntityName]: EntityType '[EntityName]' has no key defined. Define the key for this EntityType.
[EntityName]: EntityType: EntitySet '[EntityName]' is based on type '[EntityName]' that has no keys defined.
I've also got some solution for light-switch data context here Click Here
I've try to implement but not getting ApplicationData and CreateContext See Attached.
Your answer will appreciable
Thanks,
Jatin
See my article: An HTML MVC LightSwitch Security Administration (http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/3281/An-HTML-MVC-LightSwitch-Security-Administration.aspx) for an example.
Basically you need to have these includes:
using Microsoft.LightSwitch.Server;
using Microsoft.LightSwitch;
using LightSwitchApplication.Models;

C# ASP.net MVC database questions

I am trying to develop a website with C# ASP.net MVC. It's my first time using Visual Studio, C# and ASP.net so I have lots to learn but so far so good.
So far... I started a C# ASP.net MVC project and added a database by going to the Database Explorer and clicking "add connection". I then did some standard CRUD controllers and views.
I am at the stage where I want to implement User authentication. I'm a bit confused here. I am trying to make a custom Membership Provider. So I added it to my web.config file with the correct connection string etc.
When I run the project and go to register I get an error. "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'."
From searching, I see lots of people have this problem and they always reference their hosting. People say this (http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx) is their solution but when I try pick a database I get an error. Not even sure of my server name.
So at this point I am wondering, did I set up the database right?
EDIT
Adding in a few pics to show exactly what I am doing. This is the aspnet_regsql.exe:
This is the provider with connection string, taken from an example on one of the links given.
This is my customized provider with connection string pointing to the last image.
This is a screen cap when I run the project and go to the default project Account register action:
and finally, this is the error screen when I submit
EDIT
Another update..
I sorted something out but I am not sure if it is correct. I am now getting an error when the page loads: "Invalid object name 'dbo.Tag'"
In order to solve this problem the only thing you need to do is create an application services DB. You can achieve this by running the following command from your Visual Studio Command Prompt
aspnet_regsql
Anyways it seems that your "custom provider" isn't using a custom structure for your DB, which might be the reason why you weren't expecting this error.
If you are using the default implementation, you can access to the user administration using ASP .NET Configuration, located on your project menu in visual studio.
The default implementation uses the following conn string keyword
LocalSqlServer
The are many ways of implementing the membership provider. My guess is that probably this conn string is not pointing to your aspnet services db, you could do something like this to specify a custom location for this db
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnetdb.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
I made a blog post regarding this topic: How to use MembershipRole Provider and when to use custom implementations
It's hard to figure out anything from your post.
but when I try pick a database I get
an error.
You can check your server name in Surface area configuration or Sql Server Configuration Manager. If you installed Visual Studio it's probably YOUR_MACHINE_NAME\SQLEXPRESS. You can connect to it using Windows Authentication. You could also write localhost,1433 instead, but that would require enabling TCP/IP first(it's disabled by default) and setting the port number first(which in most cases is already set).

Categories

Resources