如何在网络上为Windows应用程序连接MS访问数据库 [英] How to connect MS access Database on network for windows application

查看:97
本文介绍了如何在网络上为Windows应用程序连接MS访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发c#.net中的windows基础网络应用程序,想知道如何从网络或表单服务器连接ms访问数据库。



问候

Sujit Kesbhat

I am developing windows base network application in c# .net and wants to know how to connect ms access database from network or form server pc.

Regards
Sujit Kesbhat

推荐答案

在此处查看讨论和示例代码 OLE DB - 第一步 [ ^ ]
See discussion and sample code here OLE DB - First steps[^]


Hello



不确定是否需要连接字符串或者是什么...

但是下面是你如何连接到MS Access数据库



Hello

Not sure if you want a connection string or what...
But below this is how you connect to a MS Access Database

string connString="Provider=Microsoft.Ace.OLEDB.12.0;DataSource=databasename.accdb";

       
        public DataTable getAuthentication()
        {

            using (OleDbConnection con = new OleDbConnection(connString))
            {
      OleDbCommand cmd = new OleDbCommand("SELECT * FROM tableName", con);


                DataTable dTable = new DataTable();
                OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                adapter.SelectCommand = cmd;
                adapter.Fill(dTable);

                return dTable;
            }
        } 







那么你可以在某个地方使用这个方法.. 。




Then you can use the method somewhere...


为了回应你的评论 - 按照Anele上面的解决方案进行连接,只需确保DataSource =包含共享数据库的完整服务器路径名



另请参阅 http://www.connectionstrings.com/access-2007 [ ^ ]



需要注意的事项......如果您要为您的网络位置使用驱动器映射(例如g:\ myData \ myDatabase.mdb),那么您需要确保每个人都有相同的驱动器映射,

或使用DNS名称(例如\\myServer \ MyShare \ myData \ myDatabase.mdb)
In response to your comment - connect as per Anele''s solution above, just make sure that DataSource= contains the full server path name to your shared database

See also an example at http://www.connectionstrings.com/access-2007[^]

Things to be wary of ...If you are going to use a drive mapping for your network location (e.g. g:\myData\myDatabase.mdb) then you will need to make sure that everyone has the same drive mappings,
or use the DNS name (e.g. \\myServer\MyShare\myData\myDatabase.mdb)


这篇关于如何在网络上为Windows应用程序连接MS访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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