Database connection on .mdb slows down over time - c#

Our application connects to a .mdb-file on Network. All was fine, untill we swapped the Computer from a 32-bit Windows 7 to 64 bit Windows 10. Since this action, connecting to the database through our C# code is getting slower over time. It starts with something lower than 1 second after starting the application. After running the application ca. 8 hours the opening of the database file takes more than 10 seconds, and rising. Ca. every 5 seconds the access database gets connected.
After a restart of the application all is fine. The frequently restart isn't an long term option for our customer. The queries itself are done in some ms and closing is ok, too.
I've seen that the processor usage is only about 10%. Memory i don't know at the moment.
Has anybody an idea why connecting to the database get slowed down over time?
public void OpenDb ( string _sOpenString )
{
this.sFilePathToAccessDb = _sOpenString;
this.sConnectionString =
#"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=" + this.sFilePathToAccessDb;
this.oOleDbConnection =
new System.Data.OleDb.OleDbConnection( this.sConnectionString);
this.oOleDbConnection.Open();
}
public void CloseDb()
{
if (this.oOleDbConnection != null)
{
this.oOleDbConnection.Close();
this.oOleDbConnection.Dispose();
}
this.oOleDbConnection = null;
}
public void foo()
{
OpenDb(#"\\fooserver\databases\bar.mdb");
//do some stuff
CloseDb();
}

Hence after several testing it turned out, that we've installed Microsoft Access Database Engine 2010 version 14 on the machine. After uninstall this version and install version 12.0 all is fine. Opening a Database on a network drive takes stable 30 ms.

Related

Frequent Opening and Closing of MySQL Database over Cloud

I have a local server MS-SQL situated in one of our branch. I want to transfer new data from the local server to MySql table (over the cloud) every 1 minute.
I have coded a small C# application which opens both the server connections, search and insert the new rows into MySql Database and then close the connection.
Now my question is, as I am continously opening, updating and closing the Mysql connection every minute; will there be any issues? Is there any other alternate method through which I can establish a single connection to MySql database and then keep on inserting the new rows every minute.
I appreciate your valuable support.
Below is the coding part I use to open, update and close the connection: Remember, the below method is executed every minute.
if (queryValues != "")
{
queryValues = queryValues.Remove(queryValues.Length - 1);
query = query + queryValues + ")";
MyCommand3 = new MySqlCommand(query, MyConn3);
if (MyConn3.State == 0)
MyConn3.Open();
MyReader3 = null;
MyReader3 = MyCommand3.ExecuteReader();
MyCommand3.Dispose();
MyReader3.Dispose();
MyConn3.Close();
}
It is not a problem.
Connector/NET, the MySQL driver for C#, offers connection pooling by default. That is, it keeps the connection between your program and MySQL open, so you can re-use it with another .Open() operation.
It only closes the connections when they get to be three minutes old, so you should be fine with a once-per-minute operation. And, it manages stuff like lost connections pretty well, so you don't have to.
What's more, opening a connection isn't a high-overhead operation. Only if you do it multiple times a second does the overhead get out of hand.

C#: Programmatically Detect Windows Server Has Booted

I'm working on an automation process in C# that is going to remotely reboot a Windows (2008/2012/2016) server and I need to wait until that server is back online before proceeding.
I know 'back online' can be ambiguous, so for my requirements, I need the server to be back at the Ctrl-Alt-Del screen.
The reason for this is to have the server in a consistent state before proceeding. In my experience, there are several factors that could prevent the server from reaching this screen, such as installing windows updates that gets stuck in a reboot cycle or getting stuck at 'Waiting for Local Session Manager' etc.
I've spent a few days looking in to this to no avail:
The server obviously starts responding to ping requests before it is available
System Boot Time occurs before the Server reaches the desired state
Any events indicating the system has booted are logged before the desired state
I can't simply poll for an essential service - when Windows is applying computer updates prior to logon these services can be already started. Additionally, sometimes a server will reboot itself whilst installing updates at this stage which could result in false positives.
Polling CPU activity could also produce false positives or introduce delays
Is there anyway to detect a Windows server has finished booting and is available for an interactive logon?
It sounds like you've covered most of the possible ways I know of. Which makes me revert to brute force ideas. I am curious what you're doing where you can't install a windows service on the box (or is that just not very viable because of the number)
First would just be trying to remote login or whatever, and having some way to test if it fails or not, wait 1 minute, try again. But seems like that might cause side-issues for you somehow?
My idea of a brute force method that wouldn't affect state:
Ping every 1-5seconds
Once it starts responding
wait 5 or 10 or even 15 minutes, whilst still pinging it
If pings fail reset that timer (windows updates restart case)
Then be pretty confident you're at the right state.
With potentially thousands of servers, I can't imagine 15 minutes each would be a big deal, especially if it is consistent enough to be able to run in larger batches
So I've been able to accomplish this by using a hacky method put seems to work in my test environment.
Note that the el.Current.Name property will equate to the Ctrl-Alt-Del text, so on 2008R2 this is 'Press CTRL-ALT-DEL to log on' and 'Press CTRL-ALT-DEL to sign in.' on 2012R2
I've built a C# console application that uses UI Automation:
using System;
using System.Windows.Automation;
namespace WorkstationLocked
{
class Program
{
static void Main()
{
AutomationElement el = AutomationUI.FindElementFromAutomationID("LockedMessage");
if (el !=null)
{
Console.WriteLine(el.Current.Name);
}
}
}
class AutomationUI
{
public static AutomationElement FindElementFromAutomationID(string automationID)
{
string className = "AUTHUI.DLL: LogonUI Logon Window";
PropertyCondition condition = new PropertyCondition(AutomationElement.ClassNameProperty, className);
AutomationElement logonui = AutomationElement.RootElement.FindFirst(TreeScope.Children, condition);
if (logonui != null)
{
condition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);
return logonui.FindFirst(TreeScope.Descendants, condition);
}
else
{
return null;
}
}
}
}
I can then execute this console application via PsExec, however, because this needs to be launched in the winlogon desktop, which can only be done by running under the local system, PsExec is invoked twice. For example:
psexec.exe \\ServerA -s -d C:\PsTools\PsExec.exe -accepteula -d -x C:\Utils\WorkstationLocked.exe
This is very much a work in progress right now as I can't get the output of the command to pass through to the calling process so I may just look to populate a registry value or write to a file that can be subsequently interrogated.

MYSQL degredation trouble when doing Parallel work using C#

I have a MySql server with the following config changes:
max_allowed_packet = 16M
max_connections = 2000
Innodb_cache_pool_size = 90G
I have a multi-threaded .netcore2 application executing 1000+ select queries per thread every couple of seconds.
My server environment is Ubuntu 16.04 cloud with the mysql package
This starts out fine and everything works fast but after a short amount of time, most connections change to "Sleep" mode and those who don't perform 5-10 selects every couple of seconds.
As far as resources go, I am using about 70% of all my cpus and abour 30% of my RAM.
my server is on an intranet network so I cannot copy the entire contents, but I'll try and give all the relevant info possible:
128GB RAM,
20 VCPUS (i7 cpus),
Dedicated server
All DBS are using the InnoDB engine with the Barracuda type.
Any help would be appreciated!
EDIT: as mentioned this is on an intranet network and I'm not allowed to copy any code.. I'll do my best to provide something similiar:
List<string> itemLst=new List<string>();
//fills the list here
ParallelOptions po=new ParallelOptions();
po.MaxDegreeOfParallelism = 45;
Parallel.ForEach(itemLst,po,item=>
{
//Open connection to MySql server
//do some SELECT queries
//do 1 insert and 1 delete query
//close and dispose connection
}

Running DLL/EXE program from windows service in Windows 7

I actually need an expert advice in resolving a situation regard calling InitPK.dll (C++ dll) as a service in windows 7 (Code attached). The dll is loaded successfully but PKAgentInit method is returning 0(false) on Windows 7 using windows service the same works okay in windows XP also the code works fine when exec as a console program on windows 7 .
Could you please guide us why PKAgentInit method is returning 0 on Windows 7 and what is the recommended way of calling Agent under Windows 7 using windows service.**
Code:
typedef UINT (CALLBACK* INITPK)();
m_LogDebug->Log(2,nThreadId,cMethod,
"Pre-requisite applications are running so executing Agent...");
hDll = LoadLibrary(AgentPath.c_str());
if(hDll == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load [%s]",AgentPath.c_str());
return false;
}
INITPK InitPK_Func;
if((InitPK_Func = (INITPK)GetProcAddress(HMODULE(hDll), "PKAgentInit")) == NULL)
{
m_LogDebug->Log(0,nThreadId,cMethod,
"Failed to load proc address [%s]",AgentPath.c_str());
return false;
}
UINT Res = InitPK_Func();
// returning 0 which means Agent is not executed successfully.
// Ideally it should return 1.
m_LogDebug->Log(0,nThreadId,cMethod,"PKAgentInit returned [%d]",Res);
Without seeing the source to InitPK_Func() it's hard to say but I'd guess that it's a privileges problem and the service isn't running as a user that can do what you need to do. Perhaps the code in question needs to be elevated (might be why it works on XP), or perhaps it's touching a network resource (might be why it works as a console app on Win7).
But really, you need to debug the problem function and maybe change it to return a little more information about why it failed.

C# : Problem with SqlDataSourceEnumerator.Instance.GetDataSources()

I am trying to enlist all the SQL Server instances (Local and Network) in a ComboBox by using the following code:
DataTable dt = null;
dt = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dt.Rows)
{
ComboBox1.Items.Add(dr[0].ToString() + "\\" + dr[1].ToString());
}
It works fine on Windows XP 32 Bit, Windows 7 64 Bit by enlisting all of my local and network sql server instances in the combo, but when this piece of code runs on Windows 7 32bit (All Professional version) it takes long time to fetch the instance details and ultimately fails to enlist even a single instance (which i believe due to some sort of TimeOut). The data table does not have even a single row in this case. Thus I want to ask following questions:
Does this problem is platform specific or OS specific?
Is it really due to slow network speed/ large no. of server instances on the network?
Is there any alternate to this requirement which is not platform or framework dependent as
SmoApplication.EnumAvailableSqlServers(false); // local and Network SQL instances
is framewrok dependent.
I have got at least 17-20 Network Server of SQL Server which I expect this function to return. Hence I can not understand how this could happen? I am encountering this problem precisely on Windows 7 32bit (Professional version).
Thank you
Hemant Jaiswal
This problem is more 'network specific' rather than 'OS' or 'platform'. It may work of not work depending on network settings of the machine, network configuration, firewalls etc.
This function is known for it's instability, it also can skip some servers (even if list of servers is not empty). So, my reccomendation would be to check network/firewall setting of the machines.

Categories