在网络共享上打开Firebird数据库文件 [英] Opening a Firebird database file on a network share

查看:144
本文介绍了在网络共享上打开Firebird数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为将映射的驱动器号转换为UNC路径足以打开.GDB文件,
,但是a:

I thought converting a mapped drive letter to a UNC path would be enough to be able to open a .GDB file, but alas:

function ConvertToUNCPath(AMappedDrive: string) : string;
var
   lRemoteString : array[0..255] of char;
   lpRemote      : PChar;
   lStringLen    : Cardinal;
begin
   lpRemote := @lRemoteString;
   lStringLen := 255;
   If WNetGetConnection(Pchar(ExtractFileDrive(AMappedDrive)) ,
                        lpRemote,
                        lStringLen) = NO_ERROR Then
      Result := lRemoteString
   else
      Result := ''; // No mapping found
end;

function TDataModuleData.OpenGDBDatabase(AGDBName: string) : Boolean;
var
   lDlgLogin: TFrmLogin;
   p        : Integer;
   lUNC,
   lErrMsg  : String;
begin
   Result := False;

   with FDConnection do   // TFDConnection
   begin
      Close;
      TxOptions.Isolation := xiDirtyRead;

      p := Pos(':',AGDBName);
      if p = 2 then
      begin
         lUNC := ConvertToUNCPath(Copy(AGDBName,1,2));
         if lUNC <> '' then
         begin
            lUNC := Copy(lUNC,3);
            p := pos('\',lUNC);
            AGDBName := Copy(lUNC,p) + Copy(AGDBName,3);
            lUNC := copy(lUNC,1,p-1);
         end;
      end;

      DriverName := S_FD_IBId;
      Params.Database := AGDBName;
      if lUNC <> '' then
         Params.Add('Server=' + lUNC)
      else   
         Params.Add('Server=localhost');  // Not strictly necessary

      Params.UserName := 'SYSDBA';
      Params.Password := 'masterkey';

      try
         Open;
         Result := Connected;
      except
         on E:Exception do
         begin
            lErrMsg := LowerCase(E.Message);
         end;
      end;
   end;
end;

取决于我解析 ConvertToUNCPath 结果的方式我收到不同的错误消息:

Depending on how I parse the ConvertToUNCPath result I get different error messages:


[firedac] [phys] [ib]不可用的数据库

[firedac]尝试打开文件'#$ D#$ A时,文件 persoonlijk\jan\klanten.gdb的 createfile(open)操作期间出现[phys] [ib] i / o错误'系统找不到指定的路径。

[firedac][phys][ib]unavailable database
[firedac][phys][ib]i/o error during "createfile (open)" operation for file "persoonlijk\jan\klanten.gdb"'#$D#$A'error while trying to open file'#$D#$A'the system cannot find the path specified.

使用 ConvertToUNCPath 成功转换例如 P:Jan\KLANTEN.GDB \\tt2012server\persoonlijk\Jan\KLANTEN.GDB

当路径指向映射的驱动器号时,如何打开GDB文件?

How can I open a GDB file when the path points to a mapped drive letter?

新增:我尝试了这些硬编码的变体,但都失败了:

Added: I tried these hardcoded variations, they all fail:

// lUNC := '\\2012server';  // Unable to complete network request to host
lUNC := 'tt2012server';
//AGDBName := '\\tt2012server\persoonlijk\jan\klanten.gdb';
//AGDBName := 'tt2012server\persoonlijk\jan\klanten.gdb';
//AGDBName := '\persoonlijk\jan\klanten.gdb';
//AGDBName := 'persoonlijk\jan\klanten.gdb';
//AGDBName := '\jan\klanten.gdb';
//AGDBName := 'jan\klanten.gdb';
//AGDBName := 'p:\jan\klanten.gdb'; (original input)

(P:映射到 \\tt2012server\ \persoonlijk

添加:

对不起,我不清楚初始文本:这本身与连接到远程服务器上的数据库无关。我只是希望我的本地数据库检查工具能够打开GDB文件,如果有人将其放置在我的网络共享中进行检查(而不是必须先将其复制到本地磁盘)。

To使用WNetGetConnection的唯一目的是将驱动器号解析为UNC路径(我在网上找到的一些我的代码)。

Sorry, I was not clear in my initial text: this is not about connecting to a database on a remote server per se. I just want my local 'DB inspection' tool to be able to open a GDB file if someone places it in my network share for inspection (instead of having to copy it to local disk first).
To only intention of using WNetGetConnection was to resolve drive letter to UNC path (some I code I found on the web).

推荐答案

1 。 Firebird明确拒绝尝试打开非本地磁盘上的数据库文件



Firebird是数据库服务器,因此它专注于性能和可靠性。

1. Firebird explicitly denies attempts to open database files on non-local disks

Firebird is database server, and as such it focuses on performance and reliability.

http://www.firebirdfaq.org/faq46/

性能意味着缓存了很多数据,既缓存了读取数据,又缓存了写入数据。

Performance means lots of data is cached, both cached for reading and cached for writing.

可靠性意味着Firebird具有从操作系统获得有价值的认股权证:

Reliability means Firebird has to gain worthy warrants from OS that:

a。服务器在缓存其中的一些数据以供读取时,没有其他过程可以修改数据库文件。

a. no other process would tinker with the database file while the server has some data from it cached for reading.

b。在任何时候,服务器可能希望从其缓存中将任何数据写入文件,并保证该数据-在任何时间-均以永久方式写入永久性介质。

b. at any moment in time the server might wish to write any data to the file from its cache and it is warranted that that data - at any moment in time - ends persistently written to the persistent media.

网络连接磁盘使两项担保无效,因此Firebird Server拒绝信任它们。

Network-connected disks nullify both warranties and consequently Firebird Server refuses to trust them.

您可以自行决定对Firebird配置或源文件进行破解,以如果您真正需要的不仅仅是安全性和速度,请删除此安全检查并打开网络共享文件。

You may hack Firebird configuration or source files on your own discretion to remove this safety check and open network-shared files, if you really need this more than safety and speed.

但是正确的解决方案是在磁盘所在的计算机上安装Firebird服务器确实会携带数据库文件。

But proper solution would be installing Firebird server on the machine whose disks do carry the database file.


AGDBName:='\\tt2012server\persoonlijk\ jan\klanten.gdb'

这并不意味着本地Firebird服务器应连接到 tt2012server 服务器使用 LOCAL_SYSTEM 凭据,并从 persoonlijk 读取数据库文件

This does NOT mean "local Firebird server should connect to tt2012server server using LOCAL_SYSTEM credentials and read the database file from persoonlijk shared resource", as you probably intended it to mean.

http://www.firebirdfaq.org/faq260/

如果有的话,Windows LOCAL_SYSTEM 用户已明确禁止大多数网络操作包含入侵者和病毒。即使您将Firebird入侵打开的网络文件中,除非您将Windows设置为使用默认用户 LOCAL_SYSTEM

If anything, Windows LOCAL_SYSTEM user is explicitly barred from most network operations to contain intruders and viruses. Even if you hack Firebird into opening network files, most probably Windows would prohibit this access anyway, unless you would setup your Windows to run Firebird Server service with some user account other than the default LOCAL_SYSTEM.

无论如何, \\tt2012server\persoonlijk\jan\klanten.gdb 连接字符串实际上意味着您要求您的应用程序使用 WNET (又名Microsoft命名)连接到 tt2012server

Anyway, what \\tt2012server\persoonlijk\jan\klanten.gdb Connection String actually means is that you request your application to connect to tt2012server using WNET (aka Microsoft Named Pipes) protocol and find Firebird server running on that server and communicating by WNET protocol, as opposed to TCP/IP protocol.

根据引用的错误判断-<$ c,找到运行在该服务器上并通过WNET协议(与TCP / IP协议进行通信)的Firebird服务器。

Judging by the error you quote - lUNC := '\\2012server'; // Unable to complete network request to host - the said tt2012server computer perhaps does not have a Firebird Server running and accepting Named Pipes connections.

WNET协议被认为已过时,很可能会从将来的Firebird Server版本中删除。到目前为止,它正在运行,但很少有人使用它,因此该领域几乎没有最新的经验。建议您默认使用TCP / IP协议将应用程序连接到运行在 tt2012server 计算机上而不是WNET协议的Firebird服务器。

The WNET protocol is considered obsoleted and would most probably be removed from the future Firebird Server versions. As of now it is working, but few people use it, thus little up to date experience exists in that area. It is suggested you would use TCP/IP protocol by default to connect your application to the Firebird Server running on the tt2012server machine, not WNET protocol.

  • Connecting to Firebird database from Windows local network
  • ibase_connect: remote computer host and shared db file from windows

因此,Interbase / Yaffil / Firebird系列中不可能进行脏读事务。

Consequently, there is no "dirty read" transactions possible in Interbase/Yaffil/Firebird family.

TxOptions.Isolation:= xiDirtyRead; -此行不起作用。
最有可能将其以静默方式将事务类更改为 READ COMMITTED,而不太可能给出显式错误。

TxOptions.Isolation := xiDirtyRead; - this line would not work. Most probably it would silently change the transaction class to "READ COMMITTED", less probably it would give an explicit error.

这篇关于在网络共享上打开Firebird数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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