/// <summary>
        /// 打开数据库
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="databaseType"></param>
        /// <returns></returns>
        public static ProDataSource CreateInstance(string connectionString, DatabasePlatformType databaseType)
        {
            ProDataSource dataSource = null;

            switch (databaseType)
            {
            case DatabasePlatformType.SQLServer:
                dataSource = new ProSqlServerDataSource(connectionString);
                break;

            case DatabasePlatformType.DB_Oracle:
                dataSource = new ProOracleClientDataSource(connectionString);
                break;

            case DatabasePlatformType.DB_OLEDB_Access:
                dataSource = new ProOleDataSource(connectionString);
                break;

            default:
                dataSource = new ProSqlServerDataSource(connectionString);
                break;
            }

            return(dataSource);
        }
        public static ProDataSource ConnectDataSource(string HOST, string PORT, string SID, string UserId, string Password, bool sysdba)
        {
            //使用安装登录
            ProDataSource ds      = null;
            string        exMsg   = string.Empty;
            string        connstr = CreateConnetionString(HOST, PORT, SID, UserId, Password, sysdba);

            try
            {
                ds = new ProDynamicOracleDataSource(connstr);
                ds.Open();
            }
            catch (Exception ex) { ds = null; exMsg = ex.Message; }

            //免安装的连接方式
            string file = typeof(ProDynamicOracleDataSource).Assembly.CodeBase.Substring(8) + "\\Oracle.DataAccess.dll";

            if (ds == null && System.IO.File.Exists(file))
            {
                try
                {
                    Assembly      a    = Assembly.LoadFrom(file);
                    Type          type = a.GetType("Oracle.DataAccess.Client.OracleConnection");
                    IDbConnection conn = Activator.CreateInstance(type, true) as IDbConnection;
                    conn.ConnectionString = connstr;
                    ds = new ProDynamicOracleDataSource(conn);
                    ds.Open();
                }
                catch (Exception ex) { ds = null; exMsg = exMsg + "\n" + ex.Message; }
            }

            //微软的连接
            if (ds == null)
            {
                try
                {
                    ds = ProDataSourceFactory.CreateInstance(HOST, DatabasePlatformType.DB_Oracle, "", UserId, Password);
                    ds.Open();
                }
                catch (Exception ex) { ds = null; exMsg = exMsg + "\n" + ex.Message; }
            }

            if (ds == null)
            {
                throw new ApplicationException(exMsg);
            }
            return(ds);
        }
Exemple #3
0
        public static int SPExecuteNonQuery(string spName, List <ParamPair> ppList)
        {
            ProDataSource pf = platform as ProDataSource;

            if (pf == null)
            {
                return(0);
            }
            IDbConnection conn = pf.GetConnection();

            if (conn == null)
            {
                return(0);
            }
            try
            {
                using (IDbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = string.Format("{0}.{1}", conn.Database.ToLower(), GetSPNameDialect(spName));
                    cmd.CommandType = CommandType.StoredProcedure;

                    if (ppList != null && ppList.Count > 0)
                    {
                        foreach (ParamPair pp in ppList)
                        {
                            IDbDataParameter p = cmd.CreateParameter();
                            pp.AssignParameter(p);
                            cmd.Parameters.Add(p);
                        }
                    }

                    if (cmd.Connection == null)
                    {
                        cmd.Connection = conn;
                    }

                    if (cmd.Connection.State != ConnectionState.Open)
                    {
                        cmd.Connection.Open();
                    }

                    using (IDbTransaction tran = conn.BeginTransaction())
                    {
                        try
                        {
                            cmd.CommandTimeout = 600;//360,240
                            cmd.Transaction    = tran;
                            int ret = cmd.ExecuteNonQuery();
                            try
                            {
                                tran.Commit();
                                if (pf.DBPlatformType.IsSupportedSQLServerPlatform())
                                {
                                    ret = 1;
                                }
                            }
                            catch
                            {
                                ret = 0;
                            }

                            return(ret);
                        }
                        catch (System.Exception ex)
                        {
                            LogHelper.Log(ex);
                            tran.Rollback();
                            return(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
                return(0);
            }
        }