Thread: [Adapdev-commits] Adapdev/src/Adapdev.Data DbConnectionProvider.cs,NONE,1.1 DbConnectionProviders.cs
Status: Beta
Brought to you by:
intesar66
From: Trevor L. <tre...@us...> - 2005-04-10 09:59:35
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22225/src/Adapdev.Data Modified Files: Adapdev.Data.csproj CommandTextViewer.cs ConnectionStringBuilder.cs DbProviderFactory.cs DbProviderTypeConverter.cs DbTypeConverter.cs Added Files: DbConnectionProvider.cs DbConnectionProviders.cs DbConnectionType.cs DbConnectionTypes.cs Log Message: 1. Modifications to support the ProviderConfig file for Database/Provider dynamic customisation 2. Added support classes for Oracle 3. Enhanced UI to support dynamic ProviderConfig --- NEW FILE: DbConnectionProvider.cs --- using System; using System.Collections; namespace Adapdev.Data { /// <summary> /// The ConnectionType class is a static class designed to provide a wrapper around the various types /// of connections supported by the connection Wizard. /// </summary> public class DbConnectionProvider { // Private Instance Variables private string _name = string.Empty; private string _template = string.Empty; private string _fileMask = string.Empty; private DbProviderType _type = DbProviderType.ODBC; private DbConnectionType _parent = null; private bool _enabled = true; private bool _emptyParm = false; public DbConnectionProvider() { } public DbConnectionProvider( string name, string type, string template, DbConnectionType parent) { Name = name; Template = template; ProviderTypeName = type; Parent = parent; } /// <summary> /// Functions to return a connection string for "this" Provider /// </summary> public string ConnectionString(string server) { return BuildConnectionString(this.Template, server, "", "", ""); } public string ConnectionString(string server, string database) { return BuildConnectionString(this.Template, server, database, "", ""); } public string ConnectionString(string server, string userid, string password) { return BuildConnectionString(this.Template, server, "", userid, password); } public string ConnectionString(string server, string database, string userid, string password) { return BuildConnectionString(this.Template, server, database, userid, password); } /// <summary> /// Functions to return a connection string for the "Internally used" Provider /// </summary> public string InternalProviderString(string server) { return BuildConnectionString(this.InternalProvider.Template, server, "", "", ""); } public string InternalProviderString(string server, string database) { return BuildConnectionString(this.InternalProvider.Template, server, database, "", ""); } public string InternalProviderString(string server, string userid, string password) { return BuildConnectionString(this.InternalProvider.Template, server, "", userid, password); } public string InternalProviderString(string server, string database, string userid, string password) { return BuildConnectionString(this.InternalProvider.Template, server, database, userid, password); } /// <summary> /// Returns a Connection String formatted based on the inputs /// </summary> /// <param name="server">If specified, the server location or server name</param> /// <param name="database">If specified the Name of the database or Initial Catalog</param> /// <param name="userid">If specified the UserID</param> /// <param name="password">If Specified the Password</param> /// <returns></returns> private string BuildConnectionString (string template, string server, string database, string userid, string password) { // Format the string based on the template from the configuration file string connectionString = String.Format(template, server, database, userid, password); // We need to remove any blank entries from the connection string. For example, if no UserID is // specified, rathern than having a connection string of UserID=; we remove the text between ; and =; if (!_emptyParm) { int stripTo = connectionString.IndexOf("=;"); while (stripTo > 0) { int stripFrom = connectionString.Substring(0, stripTo - 1).LastIndexOf(";"); if (stripFrom > 0) { connectionString = connectionString.Substring(0, stripFrom + 1).Trim() + (stripTo == 0 ? "" : connectionString.Substring(stripTo + 2)).Trim(); } else { connectionString = connectionString.Substring(stripTo + 2).Trim(); } stripTo = connectionString.IndexOf("=;"); } } return connectionString; } /// <summary> /// Get or Sets the Name of this Connection Object /// </summary> public string Name { get { return _name; } set { _name = value; } } /// <summary> /// True if this Provider is enabled, False if it is Disabled /// </summary> public bool Enabled { get { return _enabled; } set { _enabled = value; } } /// <summary> /// Gets or Sets the default File Mask for this provider (if a filebase provider) /// </summary> public string FileMask { get { return _parent.SupportsFile ? _fileMask : ""; } set { _fileMask = value; } } /// <summary> /// Determines if empty parameters are allowed in the connection string. /// If set to False, then empty parameters are cleaned and removed from the /// connection string when built. /// </summary> public bool AllowEmptyParameters { get { return _emptyParm; } set { _emptyParm = value; } } /// <summary> /// Gets or Sets the string used to generate the Connection String /// </summary> public string Template { get { return _template; } set { _template = value; } } /// <summary> /// Gets or sets the Provider of this Connection Type /// </summary> public DbProviderType ProviderType { get { return _type; } set { _type = value; } } /// <summary> /// Gets ort sets the Provider Type by Name /// </summary> public string ProviderTypeName { set { _type = DbProviderTypeConverter.Convert(value); } get { return DbProviderTypeConverter.Convert(_type); } } /// <summary> /// Property to Set/Get the enum of this Connection type /// </summary> public DbType DbType { get { return _parent.DbType; } set { _parent.DbType = value;} } /// <summary> /// Gets or Sets the DbType by Name rather than enum /// </summary> public string DbTypeName { get { return _parent.DbTypeName; } set { _parent.DbTypeName = value; } } /// <summary> /// Returns the OLEDB Version of this Objects Connection Reference /// </summary> public DbConnectionProvider InternalProvider { get { if (this._name.Equals(_parent.InternalProviderName)) return this; return this._parent.InternalProvider; } } /// <summary> /// Gets who the Parent is for this Provider /// </summary> public DbConnectionType Parent { get { return _parent; } set { _parent = value; } } } } Index: DbTypeConverter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/DbTypeConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DbTypeConverter.cs 28 Feb 2005 01:31:46 -0000 1.1.1.1 --- DbTypeConverter.cs 10 Apr 2005 09:59:21 -0000 1.2 *************** *** 27,30 **** } } } ! } \ No newline at end of file --- 27,48 ---- } } + + public static string Convert(DbType t) { + switch (t) { + case DbType.ACCESS: + return "ACCESS"; + case DbType.DB2: + return "DB2"; + case DbType.MYSQL: + return "MYSQL"; + case DbType.ORACLE: + return "ORACLE"; + case DbType.SQLSERVER: + return "SQLSERVER"; + default: + throw new Exception("DbType " + t.ToString() + " not found."); + } + } + } ! } Index: DbProviderTypeConverter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/DbProviderTypeConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DbProviderTypeConverter.cs 28 Feb 2005 01:31:46 -0000 1.1.1.1 --- DbProviderTypeConverter.cs 10 Apr 2005 09:59:21 -0000 1.2 *************** *** 8,12 **** public class DbProviderTypeConverter { - public static DbProviderType Convert(string s) { --- 8,11 ---- *************** *** 30,33 **** --- 29,53 ---- } } + + public static string Convert(DbProviderType t) { + + switch (t) { + case DbProviderType.ODBC: + return "ODBC"; + case DbProviderType.OLEDB: + return "OLEDB"; + case DbProviderType.ORACLE: + return "ORACLE"; + case DbProviderType.SQLSERVER: + return "SQLSERVER"; + case DbProviderType.MYSQL: + return "MYSQL"; + case DbProviderType.DB2: + return "DB2"; + default: + throw new Exception("DbProviderType " + t.ToString() + " not found."); + } + } + } } \ No newline at end of file --- NEW FILE: DbConnectionProviders.cs --- using System; using System.Collections; namespace Adapdev.Data { /// <summary> /// Represents a strongly-typed collection of key-and-value pairs that are /// sorted by the keys and are accessible by key and by index. /// </summary> /// <seealso cref="System.Collections.SortedList"/> [Serializable] public class DbConnectionProviders : IDictionary, ICloneable { #region Member Variables private const int DEFAULT_CAPACITY = 16; private string[] keys; private DbConnectionProvider[] values; private int count; [NonSerialized] [...1333 lines suppressed...] throw new ArgumentException("The value must be of type: " + typeof(DbConnectionProvider).FullName, "value"); return list.IndexOfValue((DbConnectionProvider)value); } public virtual int IndexOf(DbConnectionProvider value) { return list.IndexOfValue(value); } public virtual void Remove(object key) { throw new NotSupportedException("Cannot modify a read-only list."); } public virtual void RemoveAt(int index) { throw new NotSupportedException("Cannot modify a read-only list."); } } #endregion } } --- NEW FILE: DbConnectionType.cs --- using System; using System.Collections; namespace Adapdev.Data { /// <summary> /// Summary description for DBConnectionType. /// </summary> public class DbConnectionType { private string _name = ""; private string _internalProvider = ""; private DbType _dbType; private DbConnectionProviders _dbProviders; private bool _supportsServer = true; private bool _supportsName = true; private bool _supportsUserID = true; private bool _supportsPassword = true; public DbConnectionType() { _dbProviders = new DbConnectionProviders(); } public DbConnectionType( string name, DbType dbType, string provider, bool supportsServer, bool supportsName, bool supportsUserID, bool supportsPassword) : this() { Name = name; InternalProviderName= provider; DbType = dbType; SupportsServer = supportsServer; SupportsName = supportsName; SupportsUserID = supportsUserID; SupportsPassword = supportsPassword; } /// <summary> /// Property to get/set the Name of this Connection Type /// </summary> public string Name { get { return _name; } set {_name = value; } } /// <summary> /// Gets or Sets the DbType by Name rather than enum /// </summary> public string DbTypeName { get { return DbTypeConverter.Convert(_dbType); } set { _dbType = DbTypeConverter.Convert(value); } } /// <summary> /// Property to Set/Get the enum of this Connection type /// </summary> public DbType DbType { get { return _dbType; } set { _dbType = value;} } /// <summary> /// Returns a reference to the collection of available providers /// </summary> public DbConnectionProviders Providers { get { return _dbProviders;} set { _dbProviders = value;} } /// <summary> /// Allows Setting/Getting the InternalProvider which is a reference to the /// name of a Provider instance from the ProvidersCollection of the Provider /// instance which allows access to table information (normally a OLEDB connection) /// </summary> public string InternalProviderName { get {return _internalProvider; } set {_internalProvider = value;} } public DbConnectionProvider InternalProvider { get{ if (_internalProvider.Equals("") || !_dbProviders.ContainsKey(_internalProvider)) { throw new ApplicationException(String.Format("No Internal Provider defined for {0}.",this._name)); } return _dbProviders[_internalProvider]; } } /// <summary> /// Returns a provider object for a OLEDB connection type /// </summary> public DbConnectionProvider OLEDBConnection { get { if ((_internalProvider.Equals("")) || !_dbProviders.ContainsKey(_internalProvider)) { throw new ApplicationException(String.Format("No Internal Provider defined for {0}", _name)); } else { try { DbConnectionProvider provider = _dbProviders[_internalProvider]; return provider; } catch (Exception ex) { throw new ApplicationException(String.Format("Could not find the internal provider {0} for {1}\n{2}", _internalProvider, _name, ex.Message)); } } } } /// <summary> /// Returns true if this connection type supports a SERVER Name /// </summary> public bool SupportsServer { get { return _supportsServer; } set { _supportsServer = value; } } /// <summary> /// Returns true if this connection type supports a Name or Initial Catalog /// </summary> public bool SupportsName { get { return _supportsName; } set { _supportsName = value; } } /// <summary> /// Returns true if this connection type supports a UserID (Trusted do not) /// </summary> public bool SupportsUserID { get { return _supportsUserID; } set { _supportsUserID = value; } } /// <summary> /// Returns true if this connection type supports a Password /// </summary> public bool SupportsPassword { get { return _supportsPassword; } set { _supportsPassword = value; } } /// <summary> /// Returns true if this connection type supports a File DNS specifier. If Server is false /// then this connection type is a file based type. /// </summary> public bool SupportsFile { get { return !_supportsServer; } set { _supportsServer = !value; } } } } Index: DbProviderFactory.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/DbProviderFactory.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DbProviderFactory.cs 28 Feb 2005 01:31:46 -0000 1.1.1.1 --- DbProviderFactory.cs 10 Apr 2005 09:59:21 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- using System.Data.OleDb; using System.Data.SqlClient; + using System.Data.OracleClient; /// <summary> *************** *** 25,28 **** --- 26,31 ---- case DbProviderType.SQLSERVER: return new SqlCommand(); + case DbProviderType.ORACLE: + return new OracleCommand(); default: return new OleDbCommand(); *************** *** 45,48 **** --- 48,53 ---- case DbProviderType.SQLSERVER: return new SqlConnection(); + case DbProviderType.ORACLE: + return new OracleConnection(); default: return new OleDbConnection(); *************** *** 59,71 **** { case DbProviderType.SQLSERVER: ! SqlDataAdapter da = new SqlDataAdapter(); ! da.SelectCommand = (SqlCommand) command; command.Connection = connection; ! return da; default: ! OleDbDataAdapter oda = new OleDbDataAdapter(); ! oda.SelectCommand = (OleDbCommand) command; command.Connection = connection; ! return oda; } } --- 64,81 ---- { case DbProviderType.SQLSERVER: ! SqlDataAdapter sqlda = new SqlDataAdapter(); ! sqlda.SelectCommand = (SqlCommand) command; command.Connection = connection; ! return sqlda; ! case DbProviderType.ORACLE: ! OracleDataAdapter orada = new OracleDataAdapter(); ! orada.SelectCommand = (OracleCommand) command; ! command.Connection = connection; ! return orada; default: ! OleDbDataAdapter oleda = new OleDbDataAdapter(); ! oleda.SelectCommand = (OleDbCommand) command; command.Connection = connection; ! return oleda; } } Index: CommandTextViewer.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/CommandTextViewer.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** CommandTextViewer.cs 28 Feb 2005 01:31:46 -0000 1.1.1.1 --- CommandTextViewer.cs 10 Apr 2005 09:59:21 -0000 1.2 *************** *** 21,27 **** public static string Parse(IDbCommand cmd, DbProviderType providerType) { ! if (providerType == DbProviderType.OLEDB) return ParseOleDbCommand(cmd); ! else if (providerType == DbProviderType.SQLSERVER) return ParseSqlCommand(cmd); ! else throw new NotImplementedException(providerType.ToString() + " is not currently supported."); } --- 21,37 ---- public static string Parse(IDbCommand cmd, DbProviderType providerType) { ! if (providerType == DbProviderType.OLEDB) ! { ! return ParseOleDbCommand(cmd); ! } ! else if (providerType == DbProviderType.SQLSERVER) ! { ! return ParseSqlCommand(cmd); ! } ! else if (providerType == DbProviderType.ORACLE) { ! return ParseOracleCommand(cmd); ! } ! else ! throw new NotImplementedException(providerType.ToString() + " is not currently supported."); } *************** *** 172,175 **** --- 182,243 ---- } + /// <summary> + /// This is a worker method, which takes an OracleCommand and builds the sql text, + /// with the parameter values added into it. + /// </summary> + /// <param name="cmd">The command.</param> + /// <returns>A sql string with all of the parameter values filled in.</returns> + public static string ParseOracleCommand(IDbCommand cmd) { + string cmds = cmd.CommandText.ToString().Trim(); + + if (cmd.CommandType == CommandType.Text) { + for (int i = 0; i < cmd.Parameters.Count; i++) { + string pvalue = ""; + + string pname = ((IDataParameter) cmd.Parameters[i]).ParameterName; + if (((IDataParameter) cmd.Parameters[i]).Value == null) { + pvalue = DBNull.Value.ToString(); + } + else { + pvalue = ((IDataParameter) cmd.Parameters[i]).Value.ToString(); + } + string ptype = ((IDataParameter) cmd.Parameters[i]).DbType.ToString(); + + string prefix = dp.GetPrefixByName("oracle", ptype); + string newValue = prefix + pvalue + prefix; + + cmds = cmds.Replace(pname, newValue); + } + } + else if (cmd.CommandType == CommandType.StoredProcedure) { + StringBuilder sb = new StringBuilder(); + sb.Append("CREATE OR REPLACE"); + sb.Append(cmds); + for (int i = 0; i < cmd.Parameters.Count; i++) { + string pvalue = ""; + + string pname = ((IDataParameter) cmd.Parameters[i]).ParameterName; + if (((IDataParameter) cmd.Parameters[i]).Value == null) { + pvalue = DBNull.Value.ToString(); + } + else { + pvalue = ((IDataParameter) cmd.Parameters[i]).Value.ToString(); + } + string ptype = ((IDataParameter) cmd.Parameters[i]).DbType.ToString(); + + string prefix = dp.GetPrefixByName("oracle", ptype); + string newValue = prefix + pvalue + prefix; + string comma = ","; + + if (i >= cmd.Parameters.Count - 1) { + comma = ""; + } + sb.Append(" " + newValue + comma); + } + cmds = sb.ToString(); + } + return cmds; + } + } } \ No newline at end of file Index: Adapdev.Data.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Adapdev.Data.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Adapdev.Data.csproj 25 Mar 2005 02:14:29 -0000 1.3 --- Adapdev.Data.csproj 10 Apr 2005 09:59:06 -0000 1.4 *************** *** 85,88 **** --- 85,93 ---- Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> + <Reference + Name = "System.Data.OracleClient" + AssemblyName = "System.Data.OracleClient" + HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.OracleClient.dll" + /> </References> </Build> *************** *** 121,124 **** --- 126,149 ---- /> <File + RelPath = "DbConnectionProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DbConnectionProviders.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DbConnectionType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DbConnectionTypes.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "DbConstants.cs" SubType = "Code" *************** *** 361,364 **** --- 386,414 ---- /> <File + RelPath = "Sql\OracleCriteria.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Sql\OracleDeleteQuery.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Sql\OracleInsertQuery.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Sql\OracleSelectQuery.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Sql\OracleUpdateQuery.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Sql\QueryConstants.cs" SubType = "Code" *************** *** 411,414 **** --- 461,482 ---- /> <File + RelPath = "Xml\ProviderConfig.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Xml\ProviderConfig.xml" + BuildAction = "Content" + /> + <File + RelPath = "Xml\ProviderConfig.xsd" + BuildAction = "Content" + /> + <File + RelPath = "Xml\ProviderConfig.xsx" + DependentUpon = "ProviderConfig.xsd" + BuildAction = "None" + /> + <File RelPath = "Xml\ProviderInfo.cs" SubType = "code" Index: ConnectionStringBuilder.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/ConnectionStringBuilder.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ConnectionStringBuilder.cs 28 Feb 2005 01:31:46 -0000 1.1.1.1 --- ConnectionStringBuilder.cs 10 Apr 2005 09:59:21 -0000 1.2 *************** *** 1,4 **** ! namespace Adapdev.Data ! { using System; --- 1,3 ---- ! namespace Adapdev.Data { using System; *************** *** 6,13 **** /// Utility class to build connection strings /// </summary> ! public class ConnectionStringBuilder ! { ! private ConnectionStringBuilder() ! { } --- 5,23 ---- /// Utility class to build connection strings /// </summary> ! public class ConnectionStringBuilder { ! private static ProviderConfig _databases = new ProviderConfig(); ! ! private ConnectionStringBuilder() {} ! ! private ConnectionStringBuilder( string config ) { ! _databases = new ProviderConfig( config ); // Build using a override config file ! } ! ! /// <summary> ! /// Getter - Provides access to the Databases (DbConnectionTypes) collection of available ! /// database types, which in turn has available providers. ! /// </summary> ! public DbConnectionTypes Databases { ! get { return _databases.ConnectionTypes; } } *************** *** 18,24 **** /// <param name="filePath">The file path to the database</param> /// <returns></returns> ! public static string BuildAccess(DbProviderType type, string filePath) ! { ! return BuildAccess(type, filePath, "", ""); } --- 28,33 ---- /// <param name="filePath">The file path to the database</param> /// <returns></returns> ! public static string BuildAccess( DbProviderType type, string filePath ) { ! return _databases.ConnectionTypes[ "ACCESS" ].Providers[ "OLEDB" ].ConnectionString( filePath ); } *************** *** 31,45 **** /// <param name="userid">The database userid</param> /// <returns></returns> ! public static string BuildAccess(DbProviderType type, string filePath, string userid, string password) ! { ! switch (type) ! { ! case DbProviderType.OLEDB: ! return String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id={1};Password={2};", filePath, userid, password); ! case DbProviderType.ODBC: ! return String.Format(@"Driver={Microsoft Access Driver (*.mdb)};Dbq={0};Uid={1};Pwd={2};", filePath, userid, password); ! default: ! throw new ArgumentException(type.ToString() + " is not supported for this method. Please use DbType.OLEDB or DbType.ODBC"); ! } } --- 40,45 ---- /// <param name="userid">The database userid</param> /// <returns></returns> ! public static string BuildAccess( DbProviderType type, string filePath, string userid, string password ) { ! return _databases.ConnectionTypes[ "ACCESS" ].Providers[ "OLEDB" ].ConnectionString( filePath, userid, password ); } *************** *** 51,57 **** /// <param name="password">The userid</param> /// <returns></returns> ! public static string BuildDSN(string symbolicName, string userid, string password) ! { ! return String.Format("DSN={0};Uid={1};Pwd={2};", symbolicName, userid, password); } --- 51,56 ---- /// <param name="password">The userid</param> /// <returns></returns> ! public static string BuildDSN( string symbolicName, string userid, string password ) { ! return _databases.ConnectionTypes[ "ACCESS" ].Providers[ "OLEDB (DNS)" ].ConnectionString( symbolicName, userid, password ); } *************** *** 65,80 **** /// <param name="password">The password</param> /// <returns></returns> ! public static string BuildSqlServer(DbProviderType type, string server, string database, string userid, string password) ! { ! switch (type) ! { ! case DbProviderType.ODBC: ! return String.Format("Driver={SQL Server};Server={0};Database={1};Uid={2};Pwd={3};", server, database, userid, password); ! case DbProviderType.OLEDB: ! return String.Format("Provider=sqloledb;Data Source={0};Initial Catalog={1};User Id={2};Password={3};", server, database, userid, password); ! case DbProviderType.SQLSERVER: ! return String.Format("Data Source={0};Initial Catalog={1};User Id={2};Password={3};", server, database, userid, password); ! default: ! throw new Exception(type.ToString() + " is not supported. Please use DbType.ODBC, DbType.OLEDB or DbType.SQLSERVER"); } } --- 64,77 ---- /// <param name="password">The password</param> /// <returns></returns> ! public static string BuildSqlServer( DbProviderType type, string server, string database, string userid, string password ) { ! switch (type) { ! case DbProviderType.ODBC: ! return _databases.ConnectionTypes[ "SQL Server" ].Providers[ "ODBC" ].ConnectionString( server, database, userid, password ); ! case DbProviderType.OLEDB: ! return _databases.ConnectionTypes[ "SQL Server" ].Providers[ "OLEDB" ].ConnectionString( server, database, userid, password ); ! case DbProviderType.SQLSERVER: ! return _databases.ConnectionTypes[ "SQL Server" ].Providers[ "Sql Connect" ].ConnectionString( server, database, userid, password ); ! default: ! throw new Exception( type.ToString() + " is not supported. Please use DbType.ODBC, DbType.OLEDB or DbType.SQLSERVER" ); } } *************** *** 87,102 **** /// <param name="database">The database</param> /// <returns></returns> ! public static string BuildSqlServerTrusted(DbProviderType type, string server, string database) ! { ! switch (type) ! { ! case DbProviderType.ODBC: ! return String.Format("Driver={SQL Server};Server={0};Database={1};Trusted_Connection=yes;", server, database); ! case DbProviderType.OLEDB: ! return String.Format("Provider=sqloledb;Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", server, database); ! case DbProviderType.SQLSERVER: ! return String.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", server, database); ! default: ! throw new Exception(type.ToString() + " is not supported. Please use DbType.ODBC, DbType.OLEDB or DbType.SQLSERVER"); } } --- 84,97 ---- /// <param name="database">The database</param> /// <returns></returns> ! public static string BuildSqlServerTrusted( DbProviderType type, string server, string database ) { ! switch (type) { ! case DbProviderType.ODBC: ! return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "ODBC" ].ConnectionString( server, database ); ! case DbProviderType.OLEDB: ! return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "OLEDB" ].ConnectionString( server, database ); ! case DbProviderType.SQLSERVER: ! return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "Sql Connect" ].ConnectionString( server, database ); ! default: ! throw new Exception( type.ToString() + " is not supported. Please use DbType.ODBC, DbType.OLEDB or DbType.SQLSERVER" ); } } --- NEW FILE: DbConnectionTypes.cs --- using System; using System.Collections; namespace Adapdev.Data { /// <summary> /// Represents a strongly-typed collection of key-and-value pairs that are /// sorted by the keys and are accessible by key and by index. /// </summary> /// <seealso cref="System.Collections.SortedList"/> [Serializable] public class DbConnectionTypes : IDictionary, ICloneable { #region Member Variables private const int DEFAULT_CAPACITY = 16; private string[] keys; private DbConnectionType[] values; private int count; [NonSerialized] [...1333 lines suppressed...] throw new ArgumentException("The value must be of type: " + typeof(DbConnectionType).FullName, "value"); return list.IndexOfValue((DbConnectionType)value); } public virtual int IndexOf(DbConnectionType value) { return list.IndexOfValue(value); } public virtual void Remove(object key) { throw new NotSupportedException("Cannot modify a read-only list."); } public virtual void RemoveAt(int index) { throw new NotSupportedException("Cannot modify a read-only list."); } } #endregion } } |