Change Database from SQL Server to MS Access in ASP.NET MVC Project

mostafa ahmed 41 Reputation points
2022-04-03T00:35:09.787+00:00

I have developed ASP.NET MVC Project using Database created in SQL Server

I am using Database first, so I create models from database

I want to change database source from SQL Server to Microsoft Access

This the Connection string in Config file:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=DatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="DatabaseNameEntities" connectionString="metadata=res://*/DatabaseNameModel.csdl|res://*/DatabaseNameModel.ssdl|res://*/DatabaseNameModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=DatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

The problem is that ASP.NET Project create the User model by code first, but I do need that as I created the User table in database so I not need to create it by code first

The Problem in that Connection String:

<add name="DatabaseNameEntities" connectionString="metadata=res://*/DatabaseNameModel.csdl|res://*/DatabaseNameModel.ssdl|res://*/DatabaseNameModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=DatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. SurferOnWww 4,631 Reputation points
    2022-04-03T01:48:01.98+00:00

    Is your MVC application .NET Framework-based (not Core)? If so I suggest that you use the Forms Authentication which is used in the MVC4 and before. You will be able to use the Access as a store of user information if you can develop a custom membership provider for the Access.


  2. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-04-04T06:37:31.667+00:00

    Hi @mostafa ahmed ,
    You can refer to the following line for the connectionstring.
    https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbconnection.connectionstring?view=dotnet-plat-ext-6.0#system-data-oledb-oledbconnection-connectionstring

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;Jet OLEDB:Database Password=MyDbPassword;  
    

    Note: EF does not work with Access and does not support OLEDB connections.
    Microsoft strongly recommends against using Access in Web applications. For details, you can see the documentation.
    https://learn.microsoft.com/en-us/previous-versions/aspnet/jj653753(v=vs.110)?redirectedfrom=MSDN#can-my-aspnet-web-application-use-a-microsoft-access-database
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.