Source configuration
Energy.Source.Configuration builds dialect-specific connection strings. It supports SQL Server, MySQL, SQLite, PostgreSQL, Oracle, Firebird, and generic ANSI SQL.
Properties
| Property | Description |
|---|---|
Dialect |
SQL dialect from Energy.Enumeration.SqlDialect. |
Server |
Server host or instance. |
Port |
Server port. |
Catalog |
Database/catalog name. |
User |
User ID. |
Password |
Password. |
Encryption |
Enable encryption (MySQL). |
Compression |
Enable compression. |
Timeout |
Connection timeout. |
Charset |
Character set. |
Connection string
Energy.Source.Configuration config = new Energy.Source.Configuration
{
Dialect = Energy.Enumeration.SqlDialect.MYSQL,
Server = "localhost",
Catalog = "test",
User = "root",
Password = "secret",
Port = 3306,
};
string connectionString = config.ConnectionString;
Console.WriteLine(connectionString);
// Server=localhost;Port=3306;Database=test;Uid=root;Pwd=secret
Entity Framework
string ef = config.GetEntityConnectionString("MySql.Data.MySqlClient");
DSN prefix
string prefix = config.GetDSNPrefix(); // mysql
SQL Server example
Energy.Source.Configuration sql = new Energy.Source.Configuration
{
Dialect = Energy.Enumeration.SqlDialect.SQLSERVER,
Server = @".\SQLEXPRESS",
Catalog = "MyDatabase",
User = "sa",
Password = "secret",
Timeout = 10,
};
Console.WriteLine(sql.ConnectionString);
// Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;User ID=sa;Password=secret;Connect Timeout=10;
See also
core-sourceenumerationforSqlDialect