积极答复者
用c#做了个,sqlServer2005里面那个事件监控器一样的程序,启动问题请帮看看

问题
-
用c#做了个,sqlServer2005里面那个事件监控器一样的程序,可以实时查看执行的脚本以及其他信息.
然后把程序放到没有安装sqlserver2005或者说放在sqlserver2008的环境下的时候出现错误提示
(Failed to initialize object as reader.)
这个程序我只是在这个链接引用了这个dll文件,而且发布的时候这个dll文件也放在程序的目录下面.就是启动程序就报错无法进行监控.
C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll
整个程序逻辑是在没有安装sqlServer的机器上跑这个程序但是所监控的数据库是另一个服务器的.
请问这个如果不安装sqlserver2005,如何引用起来呢,是不是需要安装其他组件即可?望指教
答案
-
这一篇
http://www.cnblogs.com/huyong/p/3214456.html
(喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
,我们可以完成像SQLSERVER企业管理器一样的功能,非常强大,看你怎么使用了,在此仅抛砖引玉。我们需要在我们的项目中添加两个dll文件的引用,分别为:
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
-
我反编译了SQLSERVER的公用DLL
我安装的是SQL2005
路径:C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
发现Microsoft.SqlServer.ConnectionInfo.dll里面没有TraceServer 这个类
只有Microsoft.SqlServer.ConnectionInfoExtended这个DLL才有
我觉得LZ一定是看了这一篇文章,要做一个SQL TRACE工具出来
使用Trace Management Object监测和诊断SQL Server(一)
不好意思,路径贴出错了
SQL2005是C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies
SQL2008才是C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
SQL2012是:C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
我观察到SQL2005只有Microsoft.SqlServer.ConnectionInfo.dll DLL文件
而从SQL2008开始才有Microsoft.SqlServer.ConnectionInfoExtended.dll DLL文件
- 已编辑 Steven.桦仔 2013年11月29日 11:51 修改回复
- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
-
using Microsoft.SqlServer.Management.Common; using System; using System.Runtime.InteropServices; namespace Microsoft.SqlServer.Management.Trace { [ComVisible(false)] public class TraceServer : TraceReader { private ITraceObjectsRowsetController rowsetCtrl; public void InitializeAsReader(ConnectionInfoBase serverConnInfo, string profileFileName) { try { this.rowsetCtrl = (TraceUtils.CreateInstance("\\Binn\\pfclnt.dll", "Microsoft.SqlServer.Management.Trace.CTraceObjectsRowsetController") as ITraceObjectsRowsetController); this.rowsetCtrl.Initialize(serverConnInfo, profileFileName); this.rowsetCtrl.InitSource(false); this.traceController = this.rowsetCtrl; } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotInitializeAsReader", ex); } } public void Pause() { try { this.rowsetCtrl.Pause(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotPause", ex); } } public void Restart() { try { this.rowsetCtrl.Restart(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotRestart", ex); } } public void Stop() { try { this.rowsetCtrl.Stop(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotStop", ex); } } } }
代码里有这一个方法
public void InitializeAsReader(ConnectionInfoBase serverConnInfo, string profileFileName)
{
try
{
this.rowsetCtrl = (TraceUtils.CreateInstance("\\Binn\\pfclnt.dll", "Microsoft.SqlServer.Management.Trace.CTraceObjectsRowsetController") as ITraceObjectsRowsetController);
this.rowsetCtrl.Initialize(serverConnInfo, profileFileName);
this.rowsetCtrl.InitSource(false);
this.traceController = this.rowsetCtrl;
}
catch (Exception ex)
{
TraceUtils.FilterException(ex);
throw new SqlTraceException(typeof(StringConnectionInfo), "CannotInitializeAsReader", ex);
}
}- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
全部回复
-
不需要安装SQLSERVER的,我之前做的一个程序连接数据库实例的时候都用到过这个DLL
如何使用 SMO 的 SQL Server 2008年版本的应用程序使用 SMO 的 SQL Server 2005 版本中的新功能
-
SqlConnectionInfo connInfo = new SqlConnectionInfo(); TraceServer trcReader = new TraceServer(); connInfo.ServerName = "192.168.100"; connInfo.UserName = "sa"; connInfo.Password = "sa"; connInfo.UseIntegratedSecurity = false; string strAppPath = System.Windows.Forms.Application.StartupPath; MessageBox.Show(connInfo.ConnectionString); MessageBox.Show(strAppPath + @"\SqlMonitoring.trc"); trcReader.InitializeAsReader(connInfo, strAppPath + @"\SqlMonitoring.trc");
我用的sql2005这就是实现代码.难道有什么不妥么 -
这一篇
http://www.cnblogs.com/huyong/p/3214456.html
(喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
,我们可以完成像SQLSERVER企业管理器一样的功能,非常强大,看你怎么使用了,在此仅抛砖引玉。我们需要在我们的项目中添加两个dll文件的引用,分别为:
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
-
我反编译了SQLSERVER的公用DLL
我安装的是SQL2005
路径:C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
发现Microsoft.SqlServer.ConnectionInfo.dll里面没有TraceServer 这个类
只有Microsoft.SqlServer.ConnectionInfoExtended这个DLL才有
我觉得LZ一定是看了这一篇文章,要做一个SQL TRACE工具出来
使用Trace Management Object监测和诊断SQL Server(一)
不好意思,路径贴出错了
SQL2005是C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies
SQL2008才是C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
SQL2012是:C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
我观察到SQL2005只有Microsoft.SqlServer.ConnectionInfo.dll DLL文件
而从SQL2008开始才有Microsoft.SqlServer.ConnectionInfoExtended.dll DLL文件
- 已编辑 Steven.桦仔 2013年11月29日 11:51 修改回复
- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
-
using Microsoft.SqlServer.Management.Common; using System; using System.Runtime.InteropServices; namespace Microsoft.SqlServer.Management.Trace { [ComVisible(false)] public class TraceServer : TraceReader { private ITraceObjectsRowsetController rowsetCtrl; public void InitializeAsReader(ConnectionInfoBase serverConnInfo, string profileFileName) { try { this.rowsetCtrl = (TraceUtils.CreateInstance("\\Binn\\pfclnt.dll", "Microsoft.SqlServer.Management.Trace.CTraceObjectsRowsetController") as ITraceObjectsRowsetController); this.rowsetCtrl.Initialize(serverConnInfo, profileFileName); this.rowsetCtrl.InitSource(false); this.traceController = this.rowsetCtrl; } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotInitializeAsReader", ex); } } public void Pause() { try { this.rowsetCtrl.Pause(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotPause", ex); } } public void Restart() { try { this.rowsetCtrl.Restart(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotRestart", ex); } } public void Stop() { try { this.rowsetCtrl.Stop(); } catch (Exception ex) { TraceUtils.FilterException(ex); throw new SqlTraceException(typeof(StringConnectionInfo), "CannotStop", ex); } } } }
代码里有这一个方法
public void InitializeAsReader(ConnectionInfoBase serverConnInfo, string profileFileName)
{
try
{
this.rowsetCtrl = (TraceUtils.CreateInstance("\\Binn\\pfclnt.dll", "Microsoft.SqlServer.Management.Trace.CTraceObjectsRowsetController") as ITraceObjectsRowsetController);
this.rowsetCtrl.Initialize(serverConnInfo, profileFileName);
this.rowsetCtrl.InitSource(false);
this.traceController = this.rowsetCtrl;
}
catch (Exception ex)
{
TraceUtils.FilterException(ex);
throw new SqlTraceException(typeof(StringConnectionInfo), "CannotInitializeAsReader", ex);
}
}- 已标记为答案 Michelle GeModerator 2013年12月6日 9:11
-
LZ的问题下面这篇文章已经给出了解释:
使用Trace Management Object监测和诊断SQL Server(一)
在SQL Server 2005里TMO对象被实现在了Microsoft.SqlServer.ConnectionInfo.dll里,
在SQL Server 2008里TMO对象则被移到了Microsoft.SqlServer.ConnectionInfoExtended.dll里,
但仍然在Microsoft.SqlServer.Management.Trace命名空间里。
sqlServer2005里面那个事件监控器一样的程序,可以实时查看执行的脚本以及其他信息. 然后把程序放到没有安装sqlserver2005或者说放在sqlserver2008的环境下的时候出现错误提示