C# - connecting to an access database sitting on a web server

Soldato
Joined
8 Feb 2004
Posts
3,789
Location
London
I'm trying to write a multiplayer game (a bit like a MMORPG) where the client software (C#) connects to a central database (MS Access DB on a IIS webserver) to validate login details.

I've uploaded the testdb.mdb to my webserver, then using this code:

Code:
	string targetdb = "http://www.mywebspace.com/testdb.mdb";
	string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + targetdb;

	OleDbConnection myConnection = new OleDbConnection( connectionString );
	myConnection.Open();

	string query = "insert into tbl_users (username, password) VALUES ('john', 'test');

	OleDbCommand myCommand = new OleDbCommand();
	myCommand.CommandText = query;
	myCommand.Connection = myConnection;
	myCommand.ExecuteNonQuery();

	myConnection.Close();

The code fails - says 'Exception Details: System.Data.OleDb.OleDbException: Not a valid file name.'

If this is fundamentally not possible, could I use a mysql database? Again I think I'd have similar problems as web hosting isn't meant for hosting a database is it - unless its used locally by the web pages?

Thanks for any tips on how I can do this!
 
I don't have much experience at all with databases or web services in C#, but the reason that's not working is because you can't just point it to a remote database file like that. Direct read/write access to the file is needed, and files cannot be directly accessed via HTTP (it has to go through IIS first). What you'd need to do is set up a web service on the server with which your client app can interact in order to use the DB.
 
Last edited:
Ah yes, I had thought it would require a webservice, unfortunately I don't know much about them or whether my hosting supports it... I'll have to do some reading

thanks
 
Goksly said:
try:
string targetdb = @"http://www.mywebspace.com/testdb.mdb";

although im not sure if its that slash that gets handled differently. Worth a shot anywho :p
Nope, that would be if you were accessing a local file, as the '\' characters would otherwise be interpreted as escape characters. Anyway, the compiler would complain if the string contained invalid escape sequences. :)
 
Back
Top Bottom