<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users507</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/507" rel="self"/>
  <title>robzyc</title>
  <updated>Mon Jul 21 14:19:36 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13468</id>
    <published>2008-07-21T14:19:36-07:00</published>
    <title>[C#] On Common StProc Code</title>
    <content type="html">&lt;p&gt;Great, my thread has been hijacked!&lt;/p&gt;

&lt;p&gt;Purpose-of-website FAIL.
&lt;br /&gt;Posting-in-appropriate-thread FAIL
&lt;br /&gt;Explaining-problem-properly FAIL&lt;/p&gt;

&lt;p&gt;Running-before-you-can-walk WIN!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code/refactors/13468" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4644</id>
    <published>2008-04-02T16:29:36-07:00</published>
    <title>[C#] On Common StProc Code</title>
    <content type="html">&lt;p&gt;Yeah same here, I added it ages ago then kind of forgot about it since not much has been happening on here. Recently started trying to dedicate some time to becoming more &amp;quot;agile&amp;quot;, looking into TDD and obviously a huge part of this is the ability to refactor code effectively.&lt;/p&gt;

&lt;p&gt;Hence me coming on here and just going for it, hopefully a few others will do the same and we can bring the site back to life. I don't want to join all the peeps in the ruby crowd, I think it looks awful! =(&lt;/p&gt;

&lt;p&gt;Rated 4* since it needed a little tweak, nothing against you, it was more my fault, happy to change if people think otherwise, like I said, I'm a n00b! :)&lt;/p&gt;

&lt;p&gt;Cheers Rik!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code/refactors/4644" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4641</id>
    <published>2008-04-02T15:25:45-07:00</published>
    <title>[C#] On Common StProc Code</title>
    <content type="html">&lt;p&gt;Ah ha! Great find Rik, thanks, I have learned stuff today! :)
&lt;br /&gt;comm.Prepare() deleted!&lt;/p&gt;

&lt;p&gt;Thanks again for your help! How people gauge the ratings on this forum? Would I be right in assuming 5* is perfect?)&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code/refactors/4641" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4639</id>
    <published>2008-04-02T15:09:10-07:00</published>
    <title>[C#] On Common StProc Code</title>
    <content type="html">&lt;p&gt;OK - no problem, I will look into that more.
&lt;br /&gt;Here's what I have so far. The stored procedures that are on the server differ slightly depending on backup/restore, I don't really want to go messing this them, so I added a little code to enable the Copy method to flip things around in restore mode...&lt;/p&gt;

&lt;pre&gt;void CopyTables(List&amp;lt;TableNameResult&amp;gt; tables, int id, bool restore)
{
    using (SqlConnection conn = tgtConnStr_.CreateConnection())
    {
        // specify the sp to use and what db's are acting as source/target.
        // obviously if we are RESTORING, the data is coming from the specified
        // &amp;quot;Target&amp;quot; (i.e. snapshot DB), so we need to swap them over.
        string spName = restore ? &amp;quot;sp_RestoreSnapshotTable&amp;quot; : &amp;quot;sp_CopySourceTableToTargetTable&amp;quot;;
        string src = restore ? tgtConnStr_.DatabaseName : srcConnStr_.DatabaseName;
        string tgt = restore ? srcConnStr_.DatabaseName : tgtConnStr_.DatabaseName;

        conn.Open();

        int tblCount = tables.Count;
        int currTbl = 0;

        foreach (TableNameResult tbl in tables)
        {
            RaiseOpProgressEvent(
                new OpEventArgs(&amp;quot;Copying Table Data: '&amp;quot; + tbl.Table + &amp;quot;'&amp;quot;, tblCount, currTbl += 1));

            CopyTable(conn, src, tgt, tbl, id, spName);
        }
    }
}

void CopyTable(SqlConnection conn, string srcDB, string tgtDB,
    TableNameResult tbl, int snapshotID, string spName)
{
    using (SqlCommand comm = new SqlCommand(spName, conn))
    {
        comm.CommandType = CommandType.StoredProcedure;
        comm.Prepare();

        comm.Parameters.AddWithValue(&amp;quot;@source&amp;quot;, srcDB);
        comm.Parameters.AddWithValue(&amp;quot;@target&amp;quot;, tgtDB);
        comm.Parameters.AddWithValue(&amp;quot;@schema&amp;quot;, tbl.User);
        comm.Parameters.AddWithValue(&amp;quot;@table&amp;quot;, tbl.Table);
        comm.Parameters.AddWithValue(&amp;quot;@tableOID&amp;quot;, tbl.ID);
        comm.Parameters.AddWithValue(&amp;quot;@snapshotID&amp;quot;, snapshotID);

        comm.ExecuteNonQuery();
    }
}&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code/refactors/4639" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4635</id>
    <published>2008-04-02T13:56:56-07:00</published>
    <title>[C#] On Common StProc Code</title>
    <content type="html">&lt;p&gt;Hi Rik,
&lt;br /&gt;Thanks for the response, makes complete sense, I am making changes as I type! It certainly does read a lot better :) I never knew about AddWithValue, so thanks for that!&lt;/p&gt;

&lt;p&gt;One question though, does calling comm.Prepare for each table lose the benefit of the execution preparation?  I would have thought it needed to be called outside the loop?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code/refactors/4635" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code273</id>
    <published>2008-04-02T12:53:37-07:00</published>
    <updated>2010-11-22T08:33:45-08:00</updated>
    <title>[C#] Common StProc Code</title>
    <content type="html">&lt;p&gt;Hi guys, following my previous post to see if people still lurk here, I have decided to throw myself to the wolves and submit my first code post!&lt;/p&gt;

&lt;p&gt;With this code, I need use it twice, each one needing to use a different Stored Procedure name. So this is fine, I can bust it up to be a parameter. I am postive there is a better way to express this.&lt;/p&gt;

&lt;p&gt;I am curious to see if you guys can improve the readability, since although it makes sense, it kinda looks messy.&lt;/p&gt;

&lt;p&gt;The TableNameResult is a object that simply brings in the table info from another query.&lt;/p&gt;

&lt;p&gt;Please be nice, but please be honest, I am here to learn from you good people :)&lt;/p&gt;

&lt;p&gt;Many Thanks and Kind Regards,
&lt;br /&gt;Rob the n00b&lt;/p&gt;

&lt;pre&gt;void CopySourceTables(List&amp;lt;TableNameResult&amp;gt; tables, int id)
{
    // Execute the &amp;quot;Copy&amp;quot; Command on the Server for Each Table.
    using (SqlConnection conn = tgtConnStr_.CreateConnection())
    {
        conn.Open();
        using (SqlCommand comm = new SqlCommand(&amp;quot;sp_CopySourceTableToTargetTable&amp;quot;, conn))
        {
            // create params.
            SqlParameter source = new SqlParameter(&amp;quot;@source&amp;quot;, SqlDbType.VarChar, 255);
            source.Value = srcConnStr_.DatabaseName;
            comm.Parameters.Add(source);
            SqlParameter target = new SqlParameter(&amp;quot;@target&amp;quot;, SqlDbType.VarChar, 255);
            target.Value = tgtConnStr_.DatabaseName;
            comm.Parameters.Add(target);
            SqlParameter schema = new SqlParameter(&amp;quot;@schema&amp;quot;, SqlDbType.VarChar, 255);
            comm.Parameters.Add(schema);
            SqlParameter table = new SqlParameter(&amp;quot;@table&amp;quot;, SqlDbType.VarChar, 255);
            comm.Parameters.Add(table);
            SqlParameter tableID = new SqlParameter(&amp;quot;@tableOID&amp;quot;, SqlDbType.Int, 0);
            comm.Parameters.Add(tableID);
            SqlParameter snapshotID = new SqlParameter(&amp;quot;@snapshotID&amp;quot;, SqlDbType.Int, 0);
            comm.Parameters.Add(snapshotID);

            comm.CommandType = CommandType.StoredProcedure;
            comm.Prepare();

            int tblCount = tables.Count;
            int currTbl = 0;

            foreach (TableNameResult tbl in tables)
            {
                schema.Value = tbl.User;
                table.Value = tbl.Table;
                tableID.Value = tbl.ID;
                snapshotID.Value = id;

                RaiseOpProgressEvent(new OpEventArgs(&amp;quot;Copying Table Data: '&amp;quot; + table.Value + &amp;quot;'&amp;quot;, tblCount, currTbl += 1));

                comm.ExecuteNonQuery();
            }
        }
    }
}&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/273-common-stproc-code" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4576</id>
    <published>2008-03-31T12:01:56-07:00</published>
    <title>[C#] On Since I Cannot Message People...</title>
    <content type="html">&lt;p&gt;Hi Guys, thanks for the [prompt] responses!
&lt;br /&gt;Didn't post any code as I don't actually have any to hand that is causing my concern as yet (will review some of the code later, may have some on there!).&lt;/p&gt;

&lt;p&gt;Thanks again, appreciate it, this site looks like it could be an excellent addition to my arsenal of  &amp;quot;god I wanna be good at my job&amp;quot; tools :)&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/270-since-i-cannot-message-people/refactors/4576" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code270</id>
    <published>2008-03-31T11:03:32-07:00</published>
    <updated>2009-11-27T14:38:49-08:00</updated>
    <title>[C#] Since I Cannot Message People...</title>
    <content type="html">&lt;p&gt;Didn't/couldn't see how to message people, but this site looks like a great idea, and I could find it so useful on improving my &amp;quot;code smarter&amp;quot; abilities!&lt;/p&gt;

&lt;p&gt;So put simply, just trying to see if this place is still active/used? If not? Will it ever? :)&lt;/p&gt;

&lt;p&gt;Kind Regards,
&lt;br /&gt;Rob&lt;/p&gt;

&lt;pre&gt;bool Do_People_Still_Read_This
{
     // Not sure what to put here? &amp;quot;return true;&amp;quot; or &amp;quot;return false;&amp;quot; ?
}&lt;/pre&gt;</content>
    <author>
      <name>robzyc</name>
      <email>robc.the.geek@googlemail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/270-since-i-cannot-message-people" rel="alternate"/>
  </entry>
</feed>

