Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server/Database problem

Status
Not open for further replies.

zenox0

Programmer
Mar 28, 2005
14
CA
I have a problem where for some reason my database is not working within my server.

This is my main function:
Code:
static void Main ( string [ ] args ) 
{ 
	server.start ( PORT, MAXCONNECTIONS ); 

	// Let the program quit when they press enter 
	Console.WriteLine ( "Press Enter to exit" ); 
	Console.ReadLine ( ); 
	Console.WriteLine ( "Server finished." ); 

	// Stop the server 
	server.stop ( true ); 
}
The server class I wrote is a basic socket server that listens for connections.

Now my problem is that once my server starts up I cannot open the database (OleDb).
such as:
OleDbConnection dbCon = new OleDbConnection ( );

I setup my connection string then try to:
dbCon.Open ( );

This works perfect if I try before the:
server.start ( PORT, MAXCONNECTIONS );

However once I start the server it no longer works :S, and I have no clue why :S.

Thanks for any help.
 
Are you doing your database work in a separate thread? Because you're probably doing a blocking read on your socket, and the thread of execution stops there until it sees a connection come in.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
I have a thread that handles socket.Accept ( ) functions and for receiving data i use callbacks. I tried putting the database in its own thread but that didnt seem to work either :S.
 
What error/exception are you getting when you try and open the database?

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
It hasnt actually thrown an exception yet :S. Basically once I try to access the database Only that connection stops receiving/sending data. Any other connections are still cool and the server still receives new connections. This is my exact code for the database:

Code:
    // Static database class
    public static class Database
    {
        // Function to create a new player
        public static void NewPlayer ( )
        {
            // try.....
            try
            {
                // Get our dbConnection
                OleDbConnection dbConn = Connect ( );
                // Our database command
                OleDbCommand dbComm = new OleDbCommand ( "INSERT INTO playerTable ( playerName, playerPassword ) VALUES ( 'test', 'test' )", dbConn );
                // Open the connection
                dbConn.Open ( );
                // Execute the command
                dbComm.ExecuteNonQuery ( );
                // Close the connection
                dbConn.Close ( );
            } // End try
            // Catch anything
            catch ( Exception ex )
            {
                Console.WriteLine ( String.Format ( "Exception: {0}", ex.Message ) );
            } // End catch
        } // End new player function

        // Function to connect to a database
        private static OleDbConnection Connect ( )
        {
            // Return our new db connection
            return ( new OleDbConnection ( "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\\SharpMud.mdb" ) );
        } // End connect function

    } // End database class

Now as I said this works perfect before I start listening for a connection, inserts the data and everything. However once I try to put it into my Login function it breaks. If I debug the program and step through it the line it stops on is the dbConn.Open ( ); Once I stop debugging the program shuts down perfect and no changes to my database :(.
 
Try opening the connection before using it in your OleDbCommand creation.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
I remade my database class.. I dont have it here with me now but it works now. Instead of calling commands from within the server a function like NewPlayer will now just add a query string to a queryQueue that my new database thread reads and executes. It works now im just trying to think of a way to read information.. Think I have it figured out tho. If anyone wants me to I can post the working solution here later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top