Created
July 22, 2016 13:35
-
-
Save moh-hassan/c294ff07178e9457d78ac06f337357d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Lab demo using smo | |
//Server sql server 2012 | |
//client has smo installed for sql 2016 | |
using System; | |
using System.Data; | |
using ConsoleApplication1; | |
using Microsoft.SqlServer.Management.Common; | |
using Microsoft.SqlServer.Management.Trace; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
new Class2().Test1(); | |
TraceServer reader = new TraceServer(); | |
SqlConnectionInfo ci = new SqlConnectionInfo(); | |
ci.ServerName = @"myserver"; | |
ci.UserName = "user"; //.UseIntegratedSecurity = true; | |
ci.Password = "pw"; | |
ci.UseIntegratedSecurity = false; | |
ConnectionInfoBase connectionInfoBase = ci; | |
Console.WriteLine(ci.ConnectionString); | |
try | |
{ | |
reader.InitializeAsReader(ci, @"Standard.tdf"); | |
int eventNumber = 0; | |
while (reader.Read()) | |
{ | |
Console.Write("{0}\n", reader.GetValue(0).ToString()); | |
eventNumber++; | |
if (eventNumber == 10) break; | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex); | |
} | |
finally | |
{ | |
reader.Close(); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} | |
//------------------------------------------- | |
/* error message is raised | |
Data Source=asd-pc;User ID=sa;Password=123;MultipleActiveResultSets=False;Encryp | |
t=False;TrustServerCertificate=False | |
Microsoft.SqlServer.Management.Trace.SqlTraceException: Failed to initialize obj | |
ect as reader. ---> System.IO.FileNotFoundException: Could not load file or asse | |
mbly 'Microsoft.SqlServer.Instapi, Version=13.0.0.0, Culture=neutral, PublicKeyT | |
oken=89845dcd8080cc91' or one of its dependencies. The system cannot find the fi | |
le specified. | |
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod | |
eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& | |
stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro | |
spection, Boolean suppressSecurityChecks) | |
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code | |
Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s | |
tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros | |
pection, Boolean suppressSecurityChecks) | |
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as | |
semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMar | |
k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIn | |
trospection, Boolean suppressSecurityChecks) | |
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evid | |
ence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolea | |
n forIntrospection) | |
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evid | |
ence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) | |
at System.Reflection.Assembly.Load(String assemblyString) | |
at Microsoft.SqlServer.Management.Trace.TraceUtils.GetSqlToolsBinaryPath(Stri | |
ng appendPath) | |
at Microsoft.SqlServer.Management.Trace.TraceUtils.CreateInstance(String asse | |
mblyRelativePath, String objectClass) | |
at Microsoft.SqlServer.Management.Trace.TraceServer.InitializeAsReader(Connec | |
tionInfoBase serverConnInfo, String profileFileName) | |
--- End of inner exception stack trace --- | |
at Microsoft.SqlServer.Management.Trace.TraceServer.InitializeAsReader(Connec | |
tionInfoBase serverConnInfo, String profileFileName) | |
at ConsoleApplication2.Program.Main(String[] args) in F:\documents\Visual Stu | |
dio 2015\Projects\RowsetTrace\RowsetTrace\Program.cs:line 26 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment