951015 - 如何通过C#连接到数据库? [英] 951015 - how to connect to access database via C#?

查看:122
本文介绍了951015 - 如何通过C#连接到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Microsoft Access 2007创建一个访问数据库文件。我使用Visual Studio 2010编写需要数据库的程序。我想将该文件用作数据库。我认为这是编写快速程序来保存一些数据并对其进行管理的最简单方法。我是对的吗?

然后,在Server Explorer窗口中,我从Data Connections上下文菜单中选择Add Connection ....然后,我从启动窗口中选择Microsoft Access数据库文件,然后单击继续。我浏览文件并单击确定按钮。它错误:



没有错误信息,结果代码:E_UNEXPECTED(0x8000FFFF)



如果我点击在Test Connection按钮上,我得到相同的结果。怎么了?也许我要为我的数据库创建一些用户?



我尝试过:



首先,我不确定这是用户定义问题。然后,我不知道如何为我的数据库创建用户。我在Access菜单中调查了这一点,但没有发现任何内容。

I create an access database file by using Microsoft Access 2007. I use Visual Studio 2010 to write a program which need a database. I want to use the file as the database. I think this is the simplest way to write a rapid program to hold some data and manage them. Am I right?
Then, in the Server Explorer window, I choose Add Connection... from Data Connections context menu. Then I choose Microsoft Access Database File from the brought up window and click Continue. I browse for the file and click on OK button. It errors:

No error message available, result code: E_UNEXPECTED(0x8000FFFF)

If I click on the Test Connection button, I get the same result. What's wrong? Maybe I've to create some users for my database?

What I have tried:

First, I'm not sure it's a user definition issue. Then, I don't know how to create a user for my database. I investigated in the Access menus for this and found nothing.

推荐答案

我不认为发生了因为没有定义用户。据我所知0x8000FFFF是一个灾难性的失败,所以由于某种原因连接无法建立。



我会检查OleDb提供程序是否正确安装并且你能连接吗?使用 OleDbConnection类(系统)从代码到数据库.Data.OleDb) [ ^ ]
I wouldn't think happened because a user isn't defined. As far as I know 0x8000FFFF is a catastrophic failure so for some reason the connection cannot be established.

I would check if the OleDb provider is correctly installed and can you connect to the database from the code using OleDbConnection Class (System.Data.OleDb)[^]


我在这个答案的解决方案中提供了一个课程:



如何使用ASP.NET从WS 2012和IIS 8运行访问 [ ^ ]
I provided a class in my solution to this answer:

How do I run access from a WS 2012 and IIS 8 with ASP.NET[^]


这可能是一个问题有很多原因。
从显而易见的开始:所有用户都可以使用该文件吗?连接向导很可能没有使用您的用户ID来访问该文件,因此如果它所在的文件或teh文件夹没有所有用户所需的访问权限,那么它很容易失败。

之后,检查已安装的数据库引擎类型以连接到Access文件:ACE或JET。 JET是较旧的版本,并且在64位版本中不可用 - 所以如果尝试连接的代码是64位或任何CPU,那么再次连接就会失败。但是...... Visual Studio本身是一个32位应用程序,所以它不能直接使用64位驱动程序 - 所以如果连接测试程序实际上是VS的一部分它可能会失败,因为数据库引擎是64位而且它不能跑吧!



基本上,我们不能告诉你这样做,而且会很好 - 但如果你看起来更加悲伤那些东西,尝试修改现有的数据库连接字符串并在代码中的OleDbConnection对象中使用它:访问连接字符串 - ConnectionStrings.com [ ^ ]可能会有所帮助。
There are quite a few reasons why that may be a problem.
Start with the obvious: is the file available to all users? It's quite possible that the Connection Wizard isn't using your user ID to access the file, so if the file or teh folder it's sitting in doesn't have the required access permissions for all users, then it could easily fail.
After that, check the type of DB engine you have installed to connect to Access files: ACE or JET. JET is the older version, and isn't available in a 64 bit version - so again you could get a failure connecting there if the code trying to connect is 64 bit or "any CPU". But...Visual Studio itself is a 32 bit app, so it can't use 64 bit drivers directly - so if the connection tester is actually part of VS it could be failing because the DB engine is 64 bits and it can't run that!

Basically, we can't tell you "do this, and it'll be good" - but if you get more grief when you've looked that those things, try modifying an existing DB connection string and using it in an OleDbConnection object in your code: Access connection strings - ConnectionStrings.com[^] may well help.

这篇关于951015 - 如何通过C#连接到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆