///<summary>Turns "pooling" off, then opens the current database connection, adds that connection to the dictionary of MySqlConnections, then returns the unique ServerThread. ///The returned ServerThread can then be used later in order to stop the query in the middle of executing. ///A non-pooled connection will NOT attempt to re-use connections to the DB that already exist but are idle, ///rather it will create a brand new connection that no other connection can use. ///This is so that user queries can be safely cancelled if needed. ///Required as a first step for user queries (and ONLY user queries). ///Not currently Oracle compatible.</summary> public static int GetServerThread(bool isReportServer) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetInt(MethodBase.GetCurrentMethod(), isReportServer)); } MySqlConnection con = new MySqlConnection(); if (isReportServer) { if (ODBuild.IsWeb() && PrefC.ReportingServer.Server != "" && PrefC.ReportingServer.Database != DataConnection.GetDatabaseName()) { //Security safeguard to prevent Web users from connecting to another office's database. throw new ODException("Report server database name must match current database."); } con = new MySqlConnection( DataConnection.GetReportConnectionString( PrefC.ReportingServer.Server , PrefC.ReportingServer.Database , PrefC.ReportingServer.MySqlUser , PrefC.ReportingServer.MySqlPass) + ";pooling=false"); } else { //Use the database user with lower permissions when in Middle Tier since this method is explicitly designed for the User Query window. string connectStr = (RemotingClient.RemotingRole == RemotingRole.ServerWeb ? DataConnection.GetLowConnectionString() : DataConnection.GetCurrentConnectionString()); //all connection details are the same, except pooling should be false. con = new MySqlConnection(connectStr + ";pooling=false"); } con.Open(); int serverThread = con.ServerThread; //If the dictionary already contains the ServerThread key, then something went wrong. Just stop and throw. if (_dictCons.ContainsKey(serverThread)) { con.Close(); throw new ApplicationException("Critical error in GetServerThread: A duplicate connection was found via the server thread ID."); } lock (_lockObj) { _dictCons[serverThread] = con; } return(serverThread); }