Dear All,
I have created a small tool to trace SQL queries executed from our application. The tool is working fine with SQL server 2012 without any issues.
SqlConnectionInfo connectionInfo = new SqlConnectionInfo();
connectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["Database"];
connectionInfo.UserName = ConfigurationManager.AppSettings["UserId"];
connectionInfo.Password = ConfigurationManager.AppSettings["Password"];
connectionInfo.UseIntegratedSecurity = false;
ConnectionInfoBase connectionInfoBase = connectionInfo;
string applicationName = ConfigurationManager.AppSettings["ApplicationName"];
TraceServer trace = new TraceServer();
try
{
trace.InitializeAsReader(connectionInfoBase, ConfigurationManager.AppSettings["Template"]);
SQLTouchRunningStatus(true);
while (trace.Read())
{
if (_backgroundWorker.CancellationPending)
{
SQLTouchRunningStatus(false);
e.Cancel = true;
break;
}
string eventClass = trace["EventClass"].ToString();
if (eventClass.Equals("RPC:Completed") || eventClass.Equals("SQL:BatchCompleted"))
{
if (applicationName.Equals(trace["ApplicationName"].ToString(), StringComparison.OrdinalIgnoreCase))
{
string textData = trace["TextData"].ToString();
if (textData.Contains("network protocol"))
continue;
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
DisplayTraceData dataSource = new DisplayTraceData(GetTraceData);
this.Invoke(dataSource, new object[] { textData });
}
}
}
}
}
catch (Exception exc)
{
string message = exc.Message;
if (exc.InnerException != null)
message += ", " + exc.InnerException.Message;
if (this.InvokeRequired)
{
DisplayTraceData dataSource = new DisplayTraceData(GetTraceData);
this.Invoke(dataSource, new object[] { message });
}
}
}
However, when i try to run the same app in my colleague machine (He has SQL 2008 R2 installed, i get the below error message)
Failed to initialize object as reader., Could not load file or assembly 'Microsoft.SqlServer.Instapi, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
I try the following to solve the problem:
1) Install latest SharedManagementObjects Pacakge
2) Add assembly binding to the app config.
But still i received the same error message.
Could any one please advise me on this.
Thanks.
Best Regards,
Mohamed Nafly
- Edited by Nafly 39 minutes ago


