简体   繁体   English

在ASP.NET MVC中使用LINQ访问MYSQL数据库

[英]Accessing MYSQL database using LINQ in asp.net MVC

I want to use MYSQL database for accesssing the data in a mvc application. 我想使用MYSQL数据库访问mvc应用程序中的数据。

The connection string that i am using in web.config is: 我在web.config中使用的连接字符串是:

Then I have prepared a model,controller,view for accessing and displaying the data. 然后,我准备了用于访问和显示数据的模型,控制器,视图。

I am using LINQ o get the data from database but getting the exception:" 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)" 我正在使用LINQ o从数据库中获取数据,但遇到异常:“建立与SQL Server的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问该服务器。请验证实例名称为正确,并且SQL Server已配置为允许远程连接。(提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)”

I have also installed the MYSQL connector. 我还安装了MYSQL连接器。

Please provide me the solution to access the data using MYSQL and LINQ in MVC application 请为我提供在MVC应用程序中使用MYSQL和LINQ访问数据的解决方案

Thanks in advance. 提前致谢。

You can't use LINQ to SQL. 您不能使用LINQ to SQL。 You should use entity framework. 您应该使用实体框架。 Linq to SQL is only for MS Sql. Linq to SQL仅适用于MS Sql。 Use EF to work with any other DB, and then you can use LINQ to EF. 使用EF与任何其他数据库一起使用,然后可以使用LINQ to EF。

Linq to SQL is obsolete http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx Linq to SQL已过时http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx

Deleting my previous answer...I read your question as LINQPad, no idea why. 删除我以前的答案...我以LINQPad的身份阅读了您的问题,不知道为什么。

To be short, get a third party provider, I can't speak for others, but devart's dotConnect for Oracle has worked very well for us: Here's their MySQL version . 简而言之,找一个第三方提供商,我不能代表别人,但是devart的dotConnect for Oracle对我们来说非常有效: 这是他们的MySQL版本

You could use NHibernate and Linq-to-Nhibernate and then you are not database tied. 您可以使用NHibernate和Linq-to-Nhibernate,然后您就不会受到数据库的束缚。

NHibernate Files http://sourceforge.net/projects/nhibernate/files/ NHibernate文件http://sourceforge.net/projects/nhibernate/files/

But this I guess is dependent on how much time you have to develop! 但是我想这取决于您需要开发多少时间!

LinQ to Sql is used to Connect the MsSql to LinQ.We need third party softwares to Connect LinQ with MySql. LinQ to Sql用于将MsSql连接到LinQ。我们需要第三方软件才能将LinQ与MySql连接。 I Can Connect LinQ and Mysql with the help of DbLinq Refer this Sites 我可以在DbLinq的帮助下连接LinQ和Mysql请参阅此站点

http://www.primaryobjects.com/CMS/Article100 http://www.primaryobjects.com/CMS/Article100

https://olgatherer.wordpress.com/2010/08/19/dbmetal-isnt-hard/ https://olgatherer.wordpress.com/2010/08/19/dbmetal-isnt-hard/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM