예제 #1
0
        private string GetConnectionString()
        {
            var connectionInfo          = GetParametersForConnectionString();
            var connectionStringBuilder = new ConnectionStringBuilder(connectionInfo);

            return(connectionStringBuilder.GetConnectionString(GuiConfiguration.DatabaseProvider.InvariantName));
        }
예제 #2
0
        public void TestGetConnectionString()
        {
            TestSetConnectionString();
            ConnectionStringBuilder builder = ConnectionStringBuilder.getInstance();

            Assert.Equal(builder.GetConnectionString(), _connectionString);
        }
        public async Task <ActionResult <IEnumerable <string> > > Get([FromQuery] string country)
        {
            var cs = await csb.GetConnectionString();

            using (var connection = new SqlConnection(cs))
            {
                await connection.OpenAsync();

                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "SELECT 'Foo' AS CustomerName WHERE @Country = '' OR 'AT' = @Country UNION ALL SELECT 'Bar'";
                    cmd.Parameters.AddWithValue("@Country", string.IsNullOrEmpty(country) ? string.Empty : country);
                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        var result = new List <string>();
                        var customerNameOrdinal = reader.GetOrdinal("CustomerName");
                        while (await reader.ReadAsync())
                        {
                            result.Add(reader.GetString(customerNameOrdinal));
                        }

                        return(result);
                    }
                }
            }
        }
예제 #4
0
        private static GlobalContext OpenContext(string databaseFullPath)
        {
            ProcessesHelpers.KillOwnProcessesByName("1cv8.exe");
            var connectionStringBuilder = new ConnectionStringBuilder
            {
                Type         = Connection1CType.File,
                FileLocation = databaseFullPath,
                User         = "******",
                Password     = ""
            };
            var globalContextFactory   = new GlobalContextFactory();
            var globalContextComObject = globalContextFactory.Create(connectionStringBuilder.GetConnectionString());

            return(new GlobalContext(globalContextComObject));
        }
예제 #5
0
 public ApplicationDbContext() : base(ConnectionStringBuilder.GetConnectionString())
 {
     Database.SetInitializer <ApplicationDbContext>(new DbInitializer());
 }