0

I am using Visual studio 2017 with .NET 4.0 and Firebird ADO provider version 4.6. I'm having trouble connecting to a database file on a different server then de Web service and the Firebird service.

So for example:

Firebird host: localhost
Firebird port: 3050

Database file path: \\\\server1\C$\Databases\test.fdb

When I try to setup the connection string I create it like below:

connectionstring = "User ID=sysdba;Password=masterkey;Database=localhost/3050:\\server1\C$\Databases\test.fdb;DataSource=localhost;Port=3050;Charset=NONE;";

When I try to connect I get the message "Unavailable database". When I try the same with a Delphi project it does work, so I am sure the host, port and path all work. Is this a bug in de .NET Firebird provider or how can I fix my connection string?

How I build connection string in Delphi:

connectionstring := 'localhost/3050:\\server1\C$\Databases\test.fdb';

By the way I've tried almost every other possibility for setting the database string part.

Remi
  • 1,289
  • 1
  • 18
  • 52
  • Please show how you connect in Delphi. Knowing how you connect in Delphi, might give us a clue what you need to do in C#. However, by default Firebird server does not allow connecting to remote databases because this can corrupt databases. Databases should be located on the same host as the Firebird server process. Not to mention the fact that being able to access the C$ share is a big security risk. In short, you shouldn't be doing this at all. – Mark Rotteveel Aug 21 '19 at 08:56
  • Possible duplicate of [Opening a Firebird database file on a network share](https://stackoverflow.com/questions/49067815/opening-a-firebird-database-file-on-a-network-share) – Arioch 'The Aug 21 '19 at 09:38
  • @MarkRotteveel i've updated my question with the example connection string in Delphi – Remi Aug 21 '19 at 10:06
  • What happens if you remove `localhost/3050:` from the `Database` property. You are already specifying those through `DataSource` and `Port`. As far as I can tell the format used by Firebird ado.net for parsing that style of entry expects a normal Windows path there, so it will treat the entire value as the database name, and not as host, port, databasename. – Mark Rotteveel Aug 21 '19 at 11:16
  • @MarkRotteveel also tried this and has the same result. – Remi Aug 21 '19 at 12:12
  • @Arioch'The it's not a duplicate of that question, because this is for .NET and not Delphi – Remi Aug 21 '19 at 12:13
  • The answer there does apply to your situation: you shouldn't connect to a database through a UNC path on a different host than the database, and it will only work if you explicitly disable a setting in the Firebird settings. Either you are connecting to a different Firebird server here than from Delphi, or something else is wrong. You can save yourself a lot of pain by using the recommend approach and that is having the database and Firebird on the same host. – Mark Rotteveel Aug 21 '19 at 12:21
  • @Remi - no, the answer is about Firebird server, and it is "outsize the parentheses" whether you build the connection string in Java or C# or Delphi or VB or PHP or Python or any other of dozen languages: the Firebird is still the same server regardless the language of your choice. – Arioch 'The Aug 21 '19 at 13:00
  • @MarkRotteveel I wonder if it could had just happen that in the latter example both "server1" and "localhost" is one and the same box. Or, perhaps, we just got the case of proxying, of "server chaining" ? – Arioch 'The Aug 21 '19 at 13:03
  • And since Jaybird by default drops Firebird Client and re-implements it down to wire protocol, I wonder ,does Jaybird natively support server chaining or not ? Or it should not matter here and chaining is done (or not) in the Yvalve of the target server, not in the local client, be it fbclient or jaybird? – Arioch 'The Aug 21 '19 at 13:11
  • Also, was `connectionstring = " ....Database=localhost/3050:\\server1\C$\...` verbatim copied off the C# sources or taken from some other sources? Aren't all C-based languages a bit crazy about backslash needing to duplicate it in string literals? However in config/property files that is not necessarily so... – Arioch 'The Aug 21 '19 at 13:24
  • @Arioch'The Server chaining is disabled by default, and is inside the server, so a client shouldn't be involved here. Also, the question is not about Jaybird. – Mark Rotteveel Aug 21 '19 at 13:28
  • Oooops, of course, CIL is not JVM, my bad :-) – Arioch 'The Aug 21 '19 at 14:16

2 Answers2

0

Try to change your statement to the following;

connectionstring = @"User ID=sysdba;Password=masterkey;Database=localhost/3050:\\server1\C$\Databases\test.fdb;DataSource=localhost;Port=3050;Charset=NONE;"

Or if you don't want to use the '@' change it to the following;

connectionstring = "User ID=sysdba;Password=masterkey;Database=localhost/3050:\\\\server1\\C$\\Databases\\test.fdb;DataSource=localhost;Port=3050;Charset=NONE;"

the backslash is interpreted as an escape character so you need to add another backslash to each backslash you don't want escaped or just use the '@' in front of the string and it will do it for you.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Ed Mendez
  • 1,510
  • 10
  • 14
0

What is your Firebird database version?

We recently have an upgrade from Firebird 2.5 to Firebird 3.0 and I had to make several changes in my project in order to make it work again. Some of them were changing the framework number, replacing the dll in references, changing firebird.conf content etc.

For your reference with firebird 3.0 I use this for connection:

Imports FirebirdSql.Data.FirebirdClient

Public con As New FbConnection("ServerType=0;User=SYSDBA;Password=bla;Size=4096;Dialect=3;Pooling=FALSE;database=localhost/3050:C:\example.FDB")
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kamores
  • 1
  • 2
  • is this VB? I do not see reverse-slashes doubled – Arioch 'The Aug 22 '19 at 07:31
  • I use Firebird 2.5 – Remi Aug 23 '19 at 11:12
  • Yes, it is Microsoft Visual Basic 2017. With firebird database 2.5 I have a project with this settings: .NET Framework 3.5 References: FirebirdSql.Data.FirebirdClient .NET 2.7.7.0 and FirebirdSql.VisualStudio.DataTools .NET 3.0.1.0 , on Visual Studio Community 2017 ver 15.3.5 The connection string is: Public con As New FbConnection("ServerType=0;User=SYSDBA;Password=bla;Size=4096;Dialect=3;Pooling=FALSE;database=192.168.0.241:C:\Mbla.FDB") – kamores Aug 23 '19 at 13:06