Exemplo n.º 1
0
        public async Task InitializeAsync()
        {
            const string connString = "Server=127.0.0.1:9089;Database=dummyifx;UID=informix;PWD=in4mix;Persist Security Info=True;Authentication=Server;";

            _connection = new DB2Connection(connString);
            await _connection.OpenAsync();
        }
Exemplo n.º 2
0
        private async Task <object> innerGetScalarAsync(string query, CancellationToken cancellationToken, int timeout = -1)
        {
            try
            {
                return(await Task.Run(async() =>
                {
                    object obj;
                    using (var asyncConnection = new DB2Connection(StringProvider.ConnectionString))
                    {
                        using (var cmd = asyncConnection.CreateCommand())
                        {
                            cmd.CommandText = query;
                            if (!IsValidTimeout(cmd, timeout))
                            {
                                throw new ArgumentException("Invalid CommandTimeout value", nameof(timeout));
                            }

                            await asyncConnection.OpenAsync(cancellationToken);

                            obj = await cmd.ExecuteScalarAsync(cancellationToken);
                        }
                    }
                    return obj;
                }, cancellationToken));
            }
            catch (Exception ex)
            {
                Logger?.LogError(ex, $"Error at GetScalarAsync; command text: {query}");
                throw new DbDataException(ex, query);
            }
        }
Exemplo n.º 3
0
        public async Task CreateObjectAsync(String command)
        {
            using (var connection = new DB2Connection(GetConnectionString()))
            {
                using (var dB2Command = connection.CreateCommand())
                {
                    dB2Command.CommandText = command;
                    if (connection.IsOpen)
                    {
                        await dB2Command.ExecuteNonQueryAsync();
                    }
                    else
                    {
                        await connection.OpenAsync();

                        await dB2Command.ExecuteNonQueryAsync();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static async Task ManageUser(string userName)
        {
            using (var connection = new DB2Connection("Server=127.0.0.1:9089;Database=dummyifx;UID=informix;PWD=in4mix;Persist Security Info=True;Authentication=Server;"))
            {
                await connection.OpenAsync();

                using (var command = new DB2Command($@"SELECT username 
                                                      FROM sysusers
                                                      WHERE username = '******';", connection))
                {
                    if (command.ExecuteScalar() != null)
                    {
                        command.CommandText = $"DROP USER {userName};";
                        command.ExecuteNonQuery();
                    }
                    command.CommandText = $"CREATE USER {userName} WITH PROPERTIES USER ifxsurr;";
                    command.ExecuteNonQuery();
                    command.CommandText = $"GRANT DBA TO {userName}";
                    command.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 5
0
 public async Task OpenAsync()
 {
     await _conn.OpenAsync();
 }