<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SQL</title>
        <link>http://geekswithblogs.net/Saqib/category/7522.aspx</link>
        <description>SQL</description>
        <language>en</language>
        <copyright>Tanzim Saqib</copyright>
        <managingEditor>me@tanzimsaqib.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>A &amp;quot;transactional&amp;quot; generic DbHelper for LINQ to SQL</title>
            <link>http://geekswithblogs.net/Saqib/archive/2008/02/29/a-quottransactionalquot-generic-dbhelper-for-linq-to-sql.aspx</link>
            <description>&lt;p&gt;In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language. You may want to make a data access layer that separates the data operation from business layer like the following:&lt;/p&gt;&lt;pre&gt;DbHelper.Insert&amp;lt;Student&amp;gt;(
    new Student()
    {
        FirstName = “Tanzim”,
        LastName = “Saqib”,
        Email = “me@TanzimSaqib.com”,
        Website = “http://www.TanzimSaqib.com”&lt;/pre&gt;&lt;pre&gt;}, true);    // Use Transaction?&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;To make use of such transactional generic DbHelper, you might want to write a singeton DbHelper class like the following. You might notice that the class is singleton, it’s static and the DataContext is being used is private, and only initialized using the connection string if not yet.&lt;/p&gt;&lt;pre&gt;public static class DbHelper
{
    private const string CONNECTION_CONFIG_NAME = “StudentServerConnectionString”;

    private static StudentServerDataContext _StudentServerDataContext = null;

    public static StudentServerDataContext GetDataContext()
    {
        if(_StudentServerDataContext == null)
            _StudentServerDataContext = new StudentServerDataContext
                (ConfigurationManager.ConnectionStrings
                [CONNECTION_CONFIG_NAME].ConnectionString);

        return _StudentServerDataContext;
    }

    public static void CleanUp()
    {
        _StudentServerDataContext.Dispose();
        _StudentServerDataContext = null;
    }

    // … code edited to save space&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;On application wide error or on end you can dispose the context so CleanUp method is useful here. To implement an Insert method see the following. You will find I have used a TransactionScope which ensures that the transaction is taking place without any interruption. If there is really any error the scope.Complete() method never gets invoked. This is how it ensures that the code inside the TransactionScope is taking place as a transaction. It is available from .NET 2.0 framework.&lt;/p&gt;&lt;pre&gt;public static void Insert&amp;lt;T&amp;gt;(T t, bool isTransactional) where T : class
{
    if (isTransactional)
    {
        using (var scope = new TransactionScope())
        {
            Insert&amp;lt;T&amp;gt;(t);

            // On any Exception, Complete() method won’t be invoked.
            // So, the transaction will be automatically rollbacked.
            scope.Complete();
        }
    }
    else
        Insert&amp;lt;T&amp;gt;(t);
}

public static void Insert&amp;lt;T&amp;gt;(T t) where T : class
{
    using (var db = GetDataContext())
    {
        db.GetTable&amp;lt;T&amp;gt;().InsertOnSubmit(t);

        try
        {
            db.SubmitChanges();
        }
        catch (Exception e)
        {
            // TODO: log Exception
            throw e;
        }
    }
}&lt;/pre&gt;
&lt;p&gt;I did not show other methods as part of the CRUD implementation. The rest is left open for you to implement.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120075"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120075" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Saqib/aggbug/120075.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tanzim Saqib</dc:creator>
            <guid>http://geekswithblogs.net/Saqib/archive/2008/02/29/a-quottransactionalquot-generic-dbhelper-for-linq-to-sql.aspx</guid>
            <pubDate>Fri, 29 Feb 2008 02:29:09 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Saqib/comments/120075.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Saqib/archive/2008/02/29/a-quottransactionalquot-generic-dbhelper-for-linq-to-sql.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Saqib/comments/commentRss/120075.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Saqib/services/trackbacks/120075.aspx</trackback:ping>
        </item>
        <item>
            <title>SQL Server Full Text Search service running problem in Windows Vista</title>
            <link>http://geekswithblogs.net/Saqib/archive/2007/03/16/sql-server-full-text-search-service-running-problem-in-windows.aspx</link>
            <description>&lt;p&gt;I use Windows Vista Business with all features turned on. When I installed SQL Server 2005 Developer Edition, I found Full Text Search service can't start itself. I tried running it from Management Console -&amp;gt; Services. It still fails with message: "The dependency service does not exist or has been marked for deletion."&lt;/p&gt;
&lt;p&gt;So, what I did to remove the dependencies:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Opened Registry Editor (regedit.exe) &lt;/li&gt;
    &lt;li&gt;Went to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\msftesql$SQLSERVER &lt;/li&gt;
    &lt;li&gt;Removed the contents (Data) of DependOnService key &lt;/li&gt;
    &lt;li&gt;Rebooted. Now works fine. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I wasn't sure what particular dependencies were culprit, so I removed all and it works fine. Another thing to remember when you'll see any correct FullText SQL isn't working, check if the FullText service is running smoothly&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118411"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=118411" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Saqib/aggbug/118411.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tanzim Saqib</dc:creator>
            <guid>http://geekswithblogs.net/Saqib/archive/2007/03/16/sql-server-full-text-search-service-running-problem-in-windows.aspx</guid>
            <pubDate>Fri, 16 Mar 2007 15:03:53 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Saqib/comments/118411.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Saqib/archive/2007/03/16/sql-server-full-text-search-service-running-problem-in-windows.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Saqib/comments/commentRss/118411.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Saqib/services/trackbacks/118411.aspx</trackback:ping>
        </item>
    </channel>
</rss>