Connect.cs
/// <summary>
/// Writes TSQL query history to an XML file
/// </summary>
/// <param name="Guid"></param>
/// <param name="ID"></param>
/// <param name="customIn"></param>
/// <param name="customOut"></param>
Writes TSQL query history to an XML file
Writes TSQL query history to an XML file
public void CommandEvents_AfterExecute(string Guid, int ID, object customIn, object customOut)
        {
            EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.ActiveDocument.Object(null);
            if (doc != null)
            {
                string Sql = GetSQLString(doc);
                if (String.IsNullOrWhiteSpace(Sql))
                    return;
                UIConnectionInfo connInfo = ServiceCache.ScriptFactory.CurrentlyActiveWndConnectionInfo.UIConnectionInfo;
                string path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    "SSMS Query History",
                    DateTime.Now.ToString("yyyy-MMM-dd"));
                if (!System.IO.Directory.Exists(path))
                    System.IO.Directory.CreateDirectory(path);
                string filename = Path.Combine(path, "QueryHistory.xml");
                XDocument history;
                try
                {
                    history = XDocument.Load(filename);
                }
                catch (FileNotFoundException)
                {
                    history = XDocument.Parse("<SSMSQueryHistory/>");
                }
                history.Root.Add(
                    new XElement("HistoryEntry",
                        new XElement("Server", new XCData(connInfo.ServerName ?? String.Empty)),
                        new XElement("Database", new XCData(connInfo.AdvancedOptions["DATABASE"])),
                        new XElement("DateTime", DateTime.Now),
                        new XElement("Query", new XCData(Sql))));
                history.Save(filename);
            }
        }
public void CommandEvents_AfterExecute ( string Guid , int ID , object customIn , object customOut ) { EnvDTE . TextDocument doc = ( EnvDTE . TextDocument ) ServiceCache . ExtensibilityModel . ActiveDocument . Object ( null ) ; if ( doc != null ) { string Sql = GetSQLString ( doc ) ; if ( String . IsNullOrWhiteSpace ( Sql ) ) return ; UIConnectionInfo connInfo = ServiceCache . ScriptFactory . CurrentlyActiveWndConnectionInfo . UIConnectionInfo ; string path = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , " " , DateTime . Now . ToString ( " " ) ) ; if ( ! System . IO . Directory . Exists ( path ) ) System . IO . Directory . CreateDirectory ( path ) ; string filename = Path . Combine ( path , " " ) ; XDocument history ; try { history = XDocument . Load ( filename ) ; } catch ( FileNotFoundException ) { history = XDocument . Parse ( " " ) ; } history . Root . Add ( new XElement ( " " , new XElement ( " " , new XCData ( connInfo . ServerName ?? String . Empty ) ) , new XElement ( " " , new XCData ( connInfo . AdvancedOptions [ " " ] ) ) , new XElement ( " " , DateTime . Now ) , new XElement ( " " , new XCData ( Sql ) ) ) ) ; history . Save ( filename ) ; } }
Writes TSQL query history to an XML file
Writes TSQL query history to an XML file
// Get Current Connection Information // Set the path to the history file // Create the history file path if it doesn't exist // Set the filename of the history file // Attempt to load the history file and create an empty file if it doesn't exist // Add the newly executed TSQL query // Save the history file
Guid
string
None
ID
int
None
customIn
object
None
customOut
object
None