Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1.  
  2. //Lab demo using smo
  3. //Server sql server 2012
  4. //client has smo installed for sql 2016
  5.  
  6. using System;
  7. using System.Data;
  8. using ConsoleApplication1;
  9. using Microsoft.SqlServer.Management.Common;
  10. using Microsoft.SqlServer.Management.Trace;
  11.  
  12. namespace ConsoleApplication2
  13. {
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. new Class2().Test1();
  19. TraceServer reader = new TraceServer();
  20.  
  21. SqlConnectionInfo ci = new SqlConnectionInfo();
  22.  
  23. ci.ServerName = @"myserver";
  24.  
  25.  
  26. ci.UserName = "user"; //.UseIntegratedSecurity = true;
  27. ci.Password = "pw";
  28. ci.UseIntegratedSecurity = false;
  29. ConnectionInfoBase connectionInfoBase = ci;
  30. Console.WriteLine(ci.ConnectionString);
  31.  
  32. try
  33. {
  34. reader.InitializeAsReader(ci, @"Standard.tdf");
  35.  
  36. int eventNumber = 0;
  37.  
  38. while (reader.Read())
  39. {
  40. Console.Write("{0}\n", reader.GetValue(0).ToString());
  41. eventNumber++;
  42. if (eventNumber == 10) break;
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. Console.WriteLine(ex);
  48. }
  49. finally
  50. {
  51. reader.Close();
  52. }
  53. Console.ReadLine();
  54.  
  55.  
  56. }
  57.  
  58. }
  59. }
  60.  
  61.  
  62. //-------------------------------------------
  63. /* error message is raised
  64. Data Source=asd-pc;User ID=sa;Password=123;MultipleActiveResultSets=False;Encryp
  65. t=False;TrustServerCertificate=False
  66. Microsoft.SqlServer.Management.Trace.SqlTraceException: Failed to initialize obj
  67. ect as reader. ---> System.IO.FileNotFoundException: Could not load file or asse
  68. mbly 'Microsoft.SqlServer.Instapi, Version=13.0.0.0, Culture=neutral, PublicKeyT
  69. oken=89845dcd8080cc91' or one of its dependencies. The system cannot find the fi
  70. le specified.
  71. at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod
  72. eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&
  73. stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro
  74. spection, Boolean suppressSecurityChecks)
  75. at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code
  76. Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s
  77. tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros
  78. pection, Boolean suppressSecurityChecks)
  79. at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as
  80. semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMar
  81. k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIn
  82. trospection, Boolean suppressSecurityChecks)
  83. at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evid
  84. ence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolea
  85. n forIntrospection)
  86. at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evid
  87. ence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
  88. at System.Reflection.Assembly.Load(String assemblyString)
  89. at Microsoft.SqlServer.Management.Trace.TraceUtils.GetSqlToolsBinaryPath(Stri
  90. ng appendPath)
  91. at Microsoft.SqlServer.Management.Trace.TraceUtils.CreateInstance(String asse
  92. mblyRelativePath, String objectClass)
  93. at Microsoft.SqlServer.Management.Trace.TraceServer.InitializeAsReader(Connec
  94. tionInfoBase serverConnInfo, String profileFileName)
  95. --- End of inner exception stack trace ---
  96. at Microsoft.SqlServer.Management.Trace.TraceServer.InitializeAsReader(Connec
  97. tionInfoBase serverConnInfo, String profileFileName)
  98. at ConsoleApplication2.Program.Main(String[] args) in F:\documents\Visual Stu
  99. dio 2015\Projects\RowsetTrace\RowsetTrace\Program.cs:line 26
  100.  
  101. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement