Esempio n. 1
0
        private List <int> GetExternalConnectionIds()
        {
            List <int> conIds = new List <int>();
            string     sql    = "SELECT  SqlConnectionId  FROM durados_ExternaInstance WITH(NOLOCK) INNER JOIN durados_SqlConnection WITH(NOLOCK) on durados_SqlConnection.Id = durados_ExternaInstance.SqlConnectionId";

            using (System.Data.IDbConnection cnn = Durados.DataAccess.DataAccessObject.GetNewConnection(SqlProduct.SqlServer, Maps.Instance.ConnectionString))
            {
                using (DuradosCommand command = new DuradosCommand(GetSystemProduct()))
                {
                    command.Connection  = cnn;
                    command.CommandText = sql;

                    if (command.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        try
                        {
                            command.Connection.Open();
                        }
                        catch (Exception ex)
                        {
                            Maps.Instance.DuradosMap.Logger.Log("AppFactory", null, "GetExternalInstanceConnection", null, 1, "No connection to main database");
                            throw new Exception("No connection to main database", ex);
                        }
                    }
                    System.Data.IDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        conIds.Add(reader.GetInt32(reader.GetOrdinal("SqlConnectionId")));
                    }
                }
            }
            return(conIds);
        }
Esempio n. 2
0
        public string GetExternalAvailableInstanceConnectionString(SqlProduct product, out string server, out int port)
        {
            string catalog  = null;
            string username = null;
            string password = null;

            server = null;
            port   = 0;
            string spName       = "durados_GetExternalAvailableInstance";
            int?   connectionId = null;

            using (System.Data.IDbConnection cnn = Durados.DataAccess.DataAccessObject.GetNewConnection(SqlProduct.SqlServer, Maps.Instance.ConnectionString))
            {
                using (DuradosCommand command = new DuradosCommand(GetSystemProduct()))
                {
                    command.Connection  = cnn;
                    command.CommandText = spName;
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    if (command.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        try
                        {
                            command.Connection.Open();
                        }
                        catch (Exception ex)
                        {
                            Maps.Instance.DuradosMap.Logger.Log("AppFactory", null, "GetExternalAvailableInstanceConnection", null, 1, "No connection to main database");
                            throw new Exception("No connection to main database", ex);
                        }
                    }
                    System.Data.IDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        connectionId = reader.GetInt32(reader.GetOrdinal("SqlConnectionId"));
                    }
                }
            }

            if (!connectionId.HasValue)
            {
                Maps.Instance.DuradosMap.Logger.Log("AppFactory", null, "GetExternalAvailableInstanceConnection", null, 1, "Failed to retrive available external instance = connection id has no value");
                throw new Exception("Failed to retrive available external instance = connection id has no value");
            }

            Durados.Web.Mvc.View view          = GetView(ConnectionViewName);
            System.Data.DataRow  connectionRow = view.GetDataRow(connectionId.Value.ToString());
            //Dictionary<string, object> values = new Dictionary<string, object>();
            //values.Add("Id", "&&%&=&&%& " + connectionId.Value.ToString());
            //int rowCount = 0;
            //System.Data.DataView dataView = view.FillPage(1, 2, values, false, null, out rowCount, null, null);
            //if (dataView == null || rowCount != 1)
            if (connectionRow == null)
            {
                Maps.Instance.DuradosMap.Logger.Log("AppFactory", null, "GetExternalAvailableInstanceConnection", null, 1, "Failed to retrive available external instance = no data");
                throw new Exception("Failed to retrive available external instance = no data");
            }

            try
            {
                password = Convert.ToString(connectionRow["Password"]);
                username = Convert.ToString(connectionRow["Username"]);
                server   = Convert.ToString(connectionRow["ServerName"]);
                catalog  = Convert.ToString(connectionRow["Catalog"]);
                port     = Convert.ToInt32(connectionRow["ProductPort"]);
            }
            catch (Exception ex)
            {
                Maps.Instance.DuradosMap.Logger.Log("AppFactory", null, "GetExternalAvailableInstanceConnection", ex, 1, "Missing external instance parameters or converion errors");
                throw new Exception("Missing external instance parameters or converion errors");
            }
            string connectionString = GetConnectionString(server, catalog, false, username, password, null, product, port, false, false);

            return(connectionString);
        }