Com.joybase.DB.dll source Code (4)

Source: Internet
Author: User
Source Code///<summary>
Internal-protected Database connection classes
</summary>
Protected abstract class Provider
{
A static connection interface;
private static System.Data.IDbConnection Conn;
<summary>
Construction method, set to private type, is a reference to prevent invalid external;
</summary>
Protected Provider ()
{
System.Data.IDbCommand x=new System.Data.OleDb.OleDbCommand ();
}
<summary>
Returns the type of database edge connection
</summary>
public static DBType Type
{
Get
{

return provider.m_dbtype;
}
Set
{
Provider.m_dbtype=value;
}
}
private static string m_connectionstring;
private static string M_connectionstringsetname;
<summary>
Database connection string Setting name
</summary>
public static string Connectionsetname
{
Set
{
Provider.m_connectionstringsetname=value;
}
}
<summary>
Database connection string
</summary>
public static string ConnectionString
{
Set
{
Provider.m_connectionstring=value;
}
}
private static DBType M_dbtype;

<summary>
Get Database Connection interface
</summary>
<returns> return a connection </returns>
public static System.Data.IDbConnection Getconn ()
{
String Connstr= "";
try{
System.Threading.Thread.GetDomain (). Unhandledexception+=new Unhandledexceptioneventhandler (throwdbexception);
if (provider.m_connectionstring== "" | | Provider.m_connectionstring==null)
{
if (Provider.m_ConnectionStringSetName.Trim () = "")
{
connstr=system.configuration.configurationsettings.appsettings["Database.connectionstring"];
}
Else
{
Connstr=system.configuration.configurationsettings.appsettings[provider.m_connectionstringsetname];
}

}
Else
{
connstr=provider.m_connectionstring;
}
if (connstr==null| | connstr== "")
{
throw new Joybasedbexception ("The connection string is empty or is a null type, check your connectionstring and connectionsetname for proper setting, or read the instructions.");
}
DBType M_dbtype;//=provider.databasetype;
/*
* Note: We have made some modifications to the previous code, in view of the System.Data.SqlClient connection
* The word "Provider" is not possible in the string, so we judge according to whether there are Provider words
* The connection is based on System.Data.SqlClient or System.Data.OleDB.
Resources
* You can set the ConnectionString property to a single cell. (You cannot specify a Provider property for a SqlConnection object.) )
*– or –
*
* You can set individual properties (DataSource, Database, UserName, and so on). If you set a single property, the connection string is generated for you.
* Note that storing user names and passwords in the connection string has a security setting. For more information, see Introduction to Ado.net Connection design Tools.
*
*/
if (Connstr.tolower (). IndexOf ("provider") ==-1) provider.type=dbtype.sqlclient;
else Provider.type=dbtype.oledb;
throw new Exception ("here");

if (m_dbtype==dbtype.sqlclient)
{
Conn=new System.Data.SqlClient.SqlConnection (CONNSTR);
}
Else
{
Conn=new System.Data.OleDb.OleDbConnection (CONNSTR);
}
}
catch (Exception e)
{
String reason= "(1) The database connection string is not set, please double-check the connection string \ r \ n (2) The destination database does not exist, or the database is not started or cannot be logged in; \ r \ n (3) The connection string is not set correctly, please write it in the standard connection mode. \ r \ n ";
throw new Joybasedbexception (E.message,reason);
}
Return conn;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.