SqlServerStorage.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » DataLink » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpers » DataLink » SqlServerStorage.cs
#region "   Copyright 2005-07 to Marcos Meli - http://www.marcosmeli.com.ar" 

// Errors, suggestions, contributions, send a mail to: marcos@filehelpers.com.

#endregion

#if ! MINI
using System;
using System.Data;
using System.Data.SqlClient;

namespace FileHelpers.DataLink{
  /// <summary>This is a base class that implements the <see cref="DataStorage"/> for Microsoft SqlServer.</summary>
  public sealed class SqlServerStorage : DatabaseStorage
  {
    
    #region "  Constructors  "

    /// <summary>Create a new instance of the SqlServerStorage based on the record type provided.</summary>
    /// <param name="recordType">The type of the record class.</param>
    public SqlServerStorage(Type recordType)
            : this(recordType, string.Empty)
    {}

    /// <summary>Create a new instance of the SqlServerStorage based on the record type provided.</summary>
    /// <param name="recordType">The type of the record class.</param>
    /// <param name="connectionStr">The full conection string used to connect to the sql server.</param>
    public SqlServerStorage(Type recordType, string connectionStr)
            : base(recordType)
    {
      ConnectionString = connectionStr;
    }

    /// <summary>Create a new instance of the SqlServerStorage based on the record type provided (uses windows auth)</summary>
    /// <param name="recordType">The type of the record class.</param>
    /// <param name="server">The server name or IP of the sqlserver</param>
    /// <param name="database">The database name into the server.</param>
    public SqlServerStorage(Type recordType, string server, string database)
            : this(recordType, server, database, string.Empty,string.Empty)
    {
    }

    /// <summary>Create a new instance of the SqlServerStorage based on the record type provided (uses SqlServer auth)</summary>
    /// <param name="recordType">The type of the record class.</param>
    /// <param name="server">The server name or IP of the sqlserver</param>
    /// <param name="database">The database name into the server.</param>
    /// <param name="user">The sql username to login into the server.</param>
    /// <param name="pass">The pass of the sql username to login into the server.</param>
    public SqlServerStorage(Type recordType, string server, string database, string user, string pass)
            : this(recordType,  DataBaseHelper.SqlConnectionString(server, database, user, pass))
    {
            mServerName = server;
            mDatabaseName = database;
            mUserName = user;
      mUserPass = pass;
    }

    #endregion

    #region "  Create Connection and Command  "

    /// <summary>Must create an abstract connection object.</summary>
    /// <returns>An Abstract Connection Object.</returns>
    protected sealed override IDbConnection CreateConnection()
    {
      string conString;
      if (ConnectionString == string.Empty)
      {
        if (mServerName == null || mServerName == string.Empty)
          throw new BadUsageException("The ServerName cant be null or empty.");

        if (mDatabaseName == null || mDatabaseName == string.Empty)
          throw new BadUsageException("The DatabaseName cant be null or empty.");

        conString = DataBaseHelper.SqlConnectionString(ServerName, DatabaseName, UserName, UserPass);
      }
      else
      {
        conString = ConnectionString;
      }

      return new SqlConnection(conString);
    }

    #endregion

    #region "  ServerName  "

    private string mServerName = string.Empty;

    /// <summary> The server name or IP of the SqlServer </summary>
    public string ServerName
    {
      get { return mServerName; }
      set 
            {
                mServerName = value;
                ConnectionString = DataBaseHelper.SqlConnectionString(ServerName, DatabaseName, UserName, UserPass);
            }
    }

    #endregion

    #region "  DatabaseName  "

    private string mDatabaseName = string.Empty;
    /// <summary> The name of the database. </summary> 
    public string DatabaseName
    {
      get { return mDatabaseName; }
            set
            {
                mDatabaseName = value;
                ConnectionString = DataBaseHelper.SqlConnectionString(ServerName, DatabaseName, UserName, UserPass);
            }
    }

    #endregion

    #region "  UserName  "

    private string mUserName = string.Empty;
    /// <summary> The user name used to logon into the SqlServer. (leave empty for WindowsAuth)</summary>
    public string UserName
    {
      get { return mUserName; }
            set
            {
                mUserName = value;
                ConnectionString = DataBaseHelper.SqlConnectionString(ServerName, DatabaseName, UserName, UserPass);
            }
    }

    #endregion

    #region "  UserPass  "

    private string mUserPass = string.Empty;
    /// <summary> The user pass used to logon into the SqlServer. (leave empty for WindowsAuth)</summary>
    public string UserPass
    {
      get { return mUserPass; }
            set
            {
                mUserPass = value;
                ConnectionString = DataBaseHelper.SqlConnectionString(ServerName, DatabaseName, UserName, UserPass);
            }
    }

    #endregion

    #region "  ExecuteInBatch  "

    /// <summary></summary>
    protected override bool ExecuteInBatch
    {
      get { return true; }
    }


    #endregion

  }
}

#endif
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.