通过连接字符串连接到远程数据库 [英] Connecting to a remote database via a connection string

查看:168
本文介绍了通过连接字符串连接到远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的程序从连接在同一LAN网络(内联网)中的另一台计算机读取访问数据库。这是我正在使用的代码:

I am attempting for my program to read an access database from another computer connected in the same LAN network (intranet). This is the code that I am using:

namespace CalUnderFoot
{
    public partial class Window1 : Window
    {    
        CarsDBDataSet dataSet;
        CarsDBDataSetTableAdapters.CarSchedulingTableAdapter adapter;

        public Window1()
        {
            InitializeComponent();

            System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection()
            {
                ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= \\UNDERFOOT-PC\CalUnderFootDB\CarsDB.mdb"
            };

            con.Open();
             \\do stuff

它不会从中打开数据库

\\UNDERFOOT-PC\CalUnderFootDB\CarsDB.mdb

它仅在程序的相同位置生成其自身的另一个副本。
我知道这是一个语法问题,我是C#的新手。那我在这里想念什么?

It only generates another copy of itself in the same location of the program. I know this is a syntax issue and I am new to C#. So what am I missing here?

我仔细检查了两台计算机之间的网络连接,没关系。

I double checked the network connection between the 2 computers and it's OK.

推荐答案

我注意到您的连接字符串没有凭据。您是否尝试过这样的事情?

I notice that your connection string does not have credentials. Have you tried something like this:

Provider=Microsoft.Jet.OLEDB.4.0; 
Data Source=\\UNDERFOOT-PC\CalUnderFootDB\CarsDB.mdb;
User Id=admin; Password=;

请参阅: http://www.connectionstrings.com/access-2003/

这篇关于通过连接字符串连接到远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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