English 中文(简体)
协助建立联系
原标题:Help with connection string

因此,我试图与我的数据库在具体地点连接起来,只要在数据来源领域指定的同一地点安装灯塔,就能够建立联系,但如果我试图分发我的申请,档案途径将改变,并导致我想避免的错误。 我在此强调:

string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersPC1DocumentsVisual Studio 2008ProjectsTestTestinDebugMyDatabase01.accdb;Persist Security Info=true";

我是否可以确定数据来源的位置是否在同一方面?

最佳回答

If you can t use a relative path in connection string, you can generate it at runtime something like:

string connstring = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=true", Path.Combine(Directory.GetCurrentDirectory(), "MyDatabase01.accdb"));
问题回答

我可以想做几个事情:

  1. 在申请之后将数据库储存起来,然后在连接铺设方面使用相对立案途径(这利用了ADO中修建的代号)。 净额——见here,用于更多的信息:

    string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|MyDatabase01.accdb;Persist Security Info=true";
    
  2. 在一个配置档案中储存你的联系。 当你的申请由数据库不同地点的一个机器操作时,可以改变。

  3. 您的申请是否要求先使用该数据库,然后将该地点作为环境档案存放在连接线上。

如果你在应用中分配你的数据库,选择1是最好的。 否则,我将选择3。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签