C# Visual Studio Server Explorer 是否支持自定义数据库提供程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Visual Studio Server Explorer support custom database providers?
提问by skolima
I had used Server Explorer and related tools for graphical database development with Microsoft SQL Server in some of my learning projects - and it was a great experience. However, in my work I deal with Oracle DB and SQLite and my hobby projects use MySQL (because they are hosted on Linux).
我曾在我的一些学习项目中使用服务器资源管理器和相关工具通过 Microsoft SQL Server 进行图形数据库开发 - 这是一次很棒的体验。但是,在我的工作中,我处理 Oracle DB 和 SQLite,我的爱好项目使用 MySQL(因为它们托管在 Linux 上)。
Is there a way to leverage the database-related tools in Visual Studio with other database providers?
是否可以通过其他数据库提供程序利用 Visual Studio 中与数据库相关的工具?
采纳答案by Espo
Here is instructions on how to connect to your MySQL database from Visual Studio:
以下是有关如何从 Visual Studio 连接到 MySQL 数据库的说明:
To make the connection in server explorer you need to do the following:
first of all you need to install the MyODBC connector 3.51 (or latest) on the development machine (NB. you can find this at http://www.mysql.com/products/connector/odbc/)
Create a datasource in Control Panel/Administrative Tools with a connection to your database. This data source is going to be used purely for Server Manager and you dont need to worry about creating the same data source on your clients PC when you have made your VS.NET application (Unless you want to) - I dont want to cover this in this answer, too long. For the purpose of this explanation I will pretend that you created a MyODBC data source called 'AADSN' to database 'noddy' on mysqlserver 'SERVER01' and have a root password of 'fred'. The server can be either the Computer Name (found in Control Panel/System/Computer Name), or alternatively it can be the IP Address. NB. Make sure that you test this connection before continuing with this explanation.
open your VS.NET project
go to server explorer
right-click on 'Data Connections'
select 'Add Connection'
In DataLink Properties, go to the provider tab and select "Microsoft OLE DB Provider For ODBC drivers"
Click Next
If you previously created an ODBC data source then you could just select that. The disadvantage of this is that when you install your project application on the client machine, the same data source needs to be there. I prefer to use a connection string. This should look something like:
DSN=AADSN;DESC=MySQL ODBC 3.51 Driver DSN;DATABASE=noddy;SERVER=SERVER01;UID=root;PASSWORD=fred;PORT=3306;SOCKET=;OPTION=11;STMT=;
If you omit the password from the connection string then you must make sure that the datasource you created (AADSN) contains a password. I am not going to describe what these mean, you can look in the documentation for myodbc for that, just ensure that you get a "Connection Succeeded" message when you test the datasource.
要在服务器资源管理器中建立连接,您需要执行以下操作:
首先,您需要在开发机器上安装 MyODBC 连接器 3.51(或最新版本)(注意,您可以在http://www.mysql.com/products/connector/odbc/ 上找到它 )
在控制面板/管理工具中创建一个与数据库连接的数据源。此数据源将纯粹用于服务器管理器,当您制作 VS.NET 应用程序时,您无需担心在您的客户端 PC 上创建相同的数据源(除非您愿意) - 我不想涵盖这一点在这个答案中,太长了。出于本说明的目的,我假设您在 mysqlserver 'SERVER01' 上为数据库 'noddy' 创建了一个名为 'AADSN' 的 MyODBC 数据源,并且有一个 root 密码为 'fred'。服务器可以是计算机名称(在控制面板/系统/计算机名称中找到),也可以是 IP 地址。注意。在继续本说明之前,请确保测试此连接。
打开你的 VS.NET 项目
转到服务器资源管理器
右键单击“数据连接”
选择“添加连接”
在 DataLink 属性中,转到提供程序选项卡并选择“Microsoft OLE DB Provider For ODBC 驱动程序”
点击下一步
如果您之前创建了一个 ODBC 数据源,那么您可以选择它。这样做的缺点是,当您在客户端计算机上安装项目应用程序时,需要存在相同的数据源。我更喜欢使用连接字符串。这应该类似于:
DSN=AADSN;DESC=MySQL ODBC 3.51 驱动程序 DSN;DATABASE=noddy;SERVER=SERVER01;UID=root;PASSWORD=fred;PORT=3306;SOCKET=;OPTION=11;STMT=;
如果您从连接字符串中省略密码,则必须确保您创建的数据源 (AADSN) 包含密码。我不打算描述这些是什么意思,你可以查看 myodbc 的文档,只要确保在测试数据源时收到“连接成功”消息。
回答by John Hunter
The Server Explorer should support any database system that provides an ODBC driver. In the case of Oracle there is a built in driver with Visual Studio.
服务器资源管理器应支持任何提供 ODBC 驱动程序的数据库系统。对于 Oracle,Visual Studio 有一个内置驱动程序。
In the Add Connection Dialog click the change button on the data source you should then get a list of the providers you have drivers for.
在“添加连接”对话框中,单击数据源上的更改按钮,然后您应该会获得您拥有驱动程序的提供程序的列表。
回答by hitec
I found this during my research on Sqlite. I haven't had the chance to use it though. Let us know if this works for you.
我在研究 Sqlite 时发现了这一点。不过我还没有机会使用它。让我们知道这是否适合您。
http://sqlite.phxsoftware.com/
http://sqlite.phxsoftware.com/
System.Data.SQLiteSystem.Data.SQLite is the original SQLite database engine and a complete ADO.NET 2.0 provider all rolled into a single mixed mode assembly.
...
Visual Studio 2005/2008 Design-Time Support
You can add a SQLite connection to the Server Explorer, create queries with the query designer, drag-and-drop tables onto a Typed DataSet and more!
SQLite's designer works on full editions of Visual Studio 2005/2008, including VS2005 Express Editions.
NEW You can create/edit views, tables, indexes, foreign keys, constraints and triggers interactively within the Visual Studio Server Explorer!
System.Data.SQLiteSystem.Data.SQLite 是原始的 SQLite 数据库引擎和完整的 ADO.NET 2.0 提供程序,所有这些都包含在一个单一的混合模式程序集中。
...
Visual Studio 2005/2008 设计时支持
您可以将 SQLite 连接添加到服务器资源管理器、使用查询设计器创建查询、将表拖放到类型化数据集上等等!
SQLite 的设计器适用于 Visual Studio 2005/2008 的完整版本,包括 VS2005 Express Edition。
新 您可以在 Visual Studio Server Explorer 中以交互方式创建/编辑视图、表、索引、外键、约束和触发器!
回答by Brad Bruce
Oracle has a set of tools that integrates with Visual Studio. It's packaged with their data access libraries.
Oracle 有一组与 Visual Studio 集成的工具。它与他们的数据访问库打包在一起。
http://www.oracle.com/technology/software/tech/windows/odpnet/index.html
http://www.oracle.com/technology/software/tech/windows/odpnet/index.html