到本地主机的 SQL 连接
我安装 DENWER 并在内置 PhpMyAdmin 的帮助下在本地主机上创建一个数据库。当我在 C# 应用程序中连接到数据库时,我收到“SQL 异常未处理”。不明白我的错误在哪里......
代码:
SqlConnection connection = new SqlConnection("Data Source=localhost; User Id=root; Password=; Initial Catalog=MyDB");
connection.Open();
I install DENWER and with help of built-in PhpMyAdmin create a database on localhost. When i connect to database in my C# application i get "SQL Exception was unhandled". Dont understand where is my mistake...
Code:
SqlConnection connection = new SqlConnection("Data Source=localhost; User Id=root; Password=; Initial Catalog=MyDB");
connection.Open();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 phpMyAdmin 是一个 MySQL 管理工具,我假设您已经实际安装了 MySQL。显然,在继续之前,您应该检查数据库是否已安装并正在运行。您可以在 phpMyAdmin 中或使用 mysql 命令行工具连接到它吗?
尝试安装 MySQL .NET 连接器,添加对 MySql.Data 程序集的引用并那么:
一般来说,如果可以的话,您应该将连接、命令和数据读取器对象包装在
using
中,以便它们得到正确处理等,或者包装在 try-finally 中并清理中的对象最后。
Since phpMyAdmin is a MySQL administration tool, I assume you've actually installed MySQL. Obviously you should check that you have a database installed and running before you go any further. Can you connect to it in phpMyAdmin or with the mysql command line tools?
Try installing the MySQL .NET connector, add a reference to the MySql.Data assembly and then:
In general you should wrap your connection, command and data reader objects in
using
if you can so that they'll get disposed properlyetc. or wrap in a try-finally and clean up the objects in the finally.