Click here to Skip to main content
15,031,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have windows application WPF. And installed in networked connected client machine. I want to access the SQLite db from admin machine that network connected. The DB located inside admin's c drive with 'qscanDBAttacheds' folder name. Here

C#
txtipaddress.Text = "100.85.138.330";
ip address.

What I have tried:

C#
private void Add_Click(object sender, RoutedEventArgs e)
       {
           myBuilder = new SQLiteConnectionStringBuilder()
           {
               DataSource = @"\\\\" + txtipaddress.Text + @"\qscanDBAttacheds\test.s3db;Version=3;New=False;Compress=True;"
           };

           SQLiteConnection con = new SQLiteConnection(myBuilder.ConnectionString);
           con.Open();
           MessageBox.Show("Success");
       }


But shown error "can not open database."

Please help me...
Posted
Updated 4-Jun-20 3:23am
v2

Sqlite is file-based only. There is no way to talk to it over TCP/IP.

Like an Access database file, you have to have the database file in a network shared folder. The path is usually going to be a UNC path, like "\\server\sharename\folderpath\databasefile".

The problem is the connection string you built isn't a connection string. It's a partial string. You have this:
DataSource = @"\\\\" + txtipaddress.Text + @"\qscanDBAttacheds\test.s3db;Version=3;New=False;Compress=True;"

The "DataSource" part has to be part of the string you build. You don't have that. You need this:
string connString = @"Data Source=\\" + txtipaddress.Text + @"\qscanDBAttacheds\test.s3db;Version=3;New=False;Compress=True;"
   
Comments
Abhilash.J.A 20-Jan-17 23:55pm
   
@Dave kreskowiak - Thank you for reply me. I have tried your advice. Then getting like connectionstring "Data Source=\\\\192.168.0.105\\qscanDBAttacheds\\test.s3db;Version=3;New=False;Compress=True;" But still it showing {"unable to open database file"} error. The db is inside another machine c drive is a path with 'qscanDBAttacheds' folder name but both are network connected. Please help me.
Abhilash.J.A 21-Jan-17 0:43am
   
I have already developed WPF windows app with SQLite db. Alternatively if its not possible in Sqlite i could migrate it in MySql. May I need a licence(paid) to distribute MySQL commercially ? I can not use paid one database. Actually, I wanted it to deploy on other machines without having to install mysql individually/saperately on each machine. Please suggest me ways...
Dave Kreskowiak 21-Jan-17 10:12am
   
OK. SQLite is a desktop database, just like Access. It's not really made for multiuser environments.

In order to get this to work, you MUST understand Windows networking and sharing. Without that, you're going to find this take impossible.

Now, if you really want a bunch of users to use the same database, you have to move to a database engine that supports such, like MySQL or SQL Server. You don't have to understand file shares but you do have to understand TCP/IP networking.

In order to use one of those engines, you must install it on a server that all of your users machines can get to on the network.
Abhilash.J.A 21-Jan-17 10:44am
   
@Dave Kreskowiak Sir, please. It is a product, then every time need to install MSSQL or MYSQL each admin's machine. How... how its possible? Please help me... I am in big trouble. OR anyway, Can I deploy on admin's machines without having to install mysql individually/saperately on each machine. Please suggest me ways.
Dave Kreskowiak 21-Jan-17 10:53am
   
The problem here is that you have no idea what you're doing with a database and you don't understand what I'm telling you.

Now, what are your applications requirements? Do you have to install the database on the same machine as the application or not? Or are you trying to have multiple instances of your application all work with the exact same copy of the database?
Abhilash.J.A 21-Jan-17 12:33pm
   
@Dave Kreskowaiak - Sir, I have created 2 .exe wpf windows application. One is for client machine (May be number of client machines) and 2nd one is for Admin machine (only one). And the machines should under common network. The client apps want to sending data to admin machine after admin apps using that client information. This is over all process. With respect to this situation, Now i wanted it to deploy on admin's machines without having to install mysql or mssql individually/saperately on each time. There is no confusion on client application, because client apps can send their data through ip address of admin machine by connectionstring. My database stands in MySql. Alternatively if its not possible in Sqlite i could migrate it in MySQL. And I can not use paid one database. Please suggest me ways.
Dave Kreskowiak 21-Jan-17 14:26pm
   
Finally! An explanation that's usable! :)

You cannot use Sqlite for this. Well, more specifically, it's a bigger pain in the ass to do it.

You can use MySQL. It just needs to be installed on the Admin workstation or on a dedicated server. BOTH of your applications need to be converted to use MySQL instead of Sqlite. The MySQL server has to be setup to accept TCP/IP connections. You then have to change the connection strings to work with MySQL. You can get the connection string format from ConnectionStrings.com[^]
Abhilash.J.A 21-Jan-17 21:11pm
   
Sir, customer demanding that they want to deploy any open source database(mysql or mssql) on admin's machines without having to install individually/saperately on each time. Can I include MySql database with the application in one installer without having to install mysql on each machine? approach like "Prerequisites in Windows Installer Deployment" ?
Dave Kreskowiak 21-Jan-17 21:13pm
   
What the "elephant" did I just tell you?!?! You install the MySQL server ONCE on the admin machine or on a dedicated server.

Then you have to run a SQL script on the MySql server to create the database and populate any initial data.
Abhilash.J.A 22-Jan-17 2:15am
   
Sorry sir, the customer not agree with install individually/saperately the MySQL server ONCE on the admin machine or on a dedicated server. The actually want all in pack. I am planing to using SQLServer's Local Database from Visual Studio 2012 for this situation instead of SQLite and MySQL or MSSql. Is this local database suite for current situation?
Dave Kreskowiak 22-Jan-17 9:46am
   
Fine, then wrap the installers for MySQL and your app under a Setup.exe that launches them.

As for LocalDB, you can't use it. It doesn't work with remote connections from other machines. It has the same limitations that you've got with Sqlite.
Abhilash.J.A 22-Jan-17 11:06am
   
Thank you sir, I will try the way by wrap the installers for MySQL with app under a Setup.exe. I don't know, how to include MySQL(xampp or wamp) inside the Setup.exe by using installshield.
In windows, instead of using "\" as file separator use "/".
   
Comments
tweber2012 25-Sep-18 9:50am
   
@hansoctantan I love you!!!!!!!!!!!!!
hansoctantan 29-Oct-18 22:13pm
   
love you too.. xD
Member 12594087 28-Jan-19 7:28am
   
Hat off!@hansoctantan. You saved my life.
Member 14128757 19-Nov-19 14:41pm
   
Thanks!
Use like this:

"Data Source=\\\\Test-PC\Db\MyDb.db"

Test-PC is network device
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900