@manhng

Welcome to my blog!

How to backup/restore a Firebird database?

May 19, 2021 16:31

How to backup/restore a Firebird database? (edit)

How to backup/restore a Firebird database? - Stack Overflow

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.9.4
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************

C:\Windows\System32>C:

C:\>cd "C:\Program Files\Firebird\Firebird_3_0\"

C:\Program Files\Firebird\Firebird_3_0>gbak -c -user SYSDBA -password masterkey C:\Git\DB\Test.bak C:\Git\DB\Test.fdb

C:\Program Files\Firebird\Firebird_3_0>

Connection String

<connectionStrings>
<add name="TestContext" connectionString="character set=none; data source=localhost;initial catalog=Test; port number=3050; user id=sysdba; dialect=3; password=masterkey;Max Pool Size=1000" providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>

Test DB Connection (DBeaver 21.0.0)

C:\>cd "C:\Program Files\Firebird\Firebird_3_0\"

C:\Program Files\Firebird\Firebird_3_0>Notepad++ databases.conf

# ------------------------------
# List of known databases
# ------------------------------

#
# Makes it possible to specify per-database configuration parameters.
# See the list of them and description on file firebird.conf.
# To place that parameters in this file add them in curly braces
# after "alias = /path/to/database.fdb" line. Example:
# big = /databases/bigdb.fdb
# {
# LockMemSize = 32M # We know that bigdb needs a lot of locks
# LockHashSlots = 19927 # and big enough hash table for them
# }
#

#
# Example Database:
#
employee.fdb = $(dir_sampleDb)/employee.fdb
employee = $(dir_sampleDb)/employee.fdb


test = C:/Git/DB/Test.FDB

#
# Master security database specific setup.
# Do not remove it until you understand well what are you doing!
#
security.db = $(dir_secDb)/security3.fdb
{
RemoteAccess = false
DefaultDbCachePages = 50
}

#
# Live Databases:
#

Result is

 

DDL Firebird + Firebird Version

April 25, 2021 22:39

DDL Firebird C# (edit)

  • Determine Firebird Version
  • How to detect the server version
  • Create Database from scratch
  • Create Table from scratch

Determine Firebird Version

SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION')
FROM rdb$database;

The database experts Doc/Firebird 3.0 DDL triggers (ibexpert.net)

How to use Firebird with .Net? (firebirdfaq.org)

Embedded Firebird: Full-Featured Embedded Database with 2 MB Runtime - CodeProject

c# - How do INSERT INTO Firebird, with autoincrement for the primary key? - Stack Overflow

Create Database + Determine Firebird Version

using FirebirdSql.Data.FirebirdClient;
using System;
using System.Data;
using System.Diagnostics;

namespace ConsoleApp1
{
class Program
{
private static string m_ConnectionString = "";

private static void Main(string[] args)
{
string exeFilePath = @"C:\Program Files\Firebird\Firebird_3_0\gstat.exe";
string firebirdDBFilePath = @"C:\Git\DB\asclepiosqualificationNew.FDB";
string exeArgs = $" -h {firebirdDBFilePath}";

//https://stackoverflow.com/questions/49338030/how-to-easily-determine-version-of-fdb-file-firebird-database
//https://stackoverflow.com/questions/15821016/c-sharp-execute-shell-command-and-get-result

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = exeFilePath;
proc.StartInfo.Arguments = exeArgs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
string[] arrOutput = output.Split(System.Environment.NewLine);
foreach (var line in arrOutput)
{
if (line.Contains("ODS version"))
{
string[] arr = line.Trim().Split("ODS version");
if (arr.Length > 0)
{
string version = arr[1].Trim();
switch (version)
{
case "10":
case "10.0":
version = "Firebird 1";
break;

case "11":
case "11.0":
case "11.2":
version = "Firebird 2.5";
break;

case "12":
case "12.0":
version = "Firebird 3";
break;

case "13":
case "13.0":
version = "Firebird 4";
break;

default:
break;
}
Console.WriteLine(version);
}
}
}

FbConnectionStringBuilder builder = new FbConnectionStringBuilder();
builder.DataSource = "localhost";
builder.UserID = "SYSDBA";
builder.Password = "masterkey";
builder.Database = "Test";
//builder.Database = @"C:\Git\DB\Test.fdb";
//builder.ServerType = FbServerType.Embedded;
builder.ServerType = FbServerType.Default;
//{"Dynamic SQL Error\r\nSQL error code = -104\r\nToken unknown - line 1, column 14\r\nUSER"}
m_ConnectionString = builder.ConnectionString;

//https://stackoverflow.com/questions/16354712/how-to-programmatically-create-firebird-database
//CreateDatabase();

//https://firebirdsql.org/manual/migration-mssql-data-types.html
//CreateTables();

//https://stackoverflow.com/questions/13402003/how-to-populate-a-datatable-from-a-stored-procedure
//CallStored();
//CallStoredProcedure();
}

private static void CreateTables()
{
//https://stackoverflow.com/questions/43020306/how-do-insert-into-firebird-with-autoincrement-for-the-primary-key (HAY)
//https://stackoverflow.com/questions/7195365/firebird-dot-net-provider-doesnt-fully-execute-query
//https://firebirdsql.org/manual/migration-mssql-data-types.html
//https://www.codeproject.com/articles/17196/firebird-sqlhelper-a-data-access-application-block
}

private static void CreateDatabase()
{
try
{
FbConnection.CreateDatabase(m_ConnectionString);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}

private static DataTable CallStoredProcedure()
{
DataTable table = new DataTable();
using (var con = new FbConnection(m_ConnectionString))
using (var cmd = new FbCommand("usp_GetUsers", con))
using (var da = new FbDataAdapter(cmd))
{
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(table);
}
return table;
}

private static DataTable CallStored()
{
var dt = new DataTable();

using (var con = new FbConnection(m_ConnectionString))
{
using (var cm = new FbCommand("usp_GetUsers", con))
{
cm.CommandType = CommandType.StoredProcedure;

using (var da = new FbDataAdapter(cm))
{
da.Fill(dt);
}
}
}

return dt;
}
}
}

Create Tables

using FirebirdSql.Data.FirebirdClient;
using FirebirdSql.Data.Isql;
using System;
using System.Diagnostics;

namespace ConsoleApp2
{
internal class Program
{
private static SolutionType solutionType = SolutionType.FbScriptFB2_5;

private static void Main(string[] args)
{
var connectionString = new FbConnectionStringBuilder
{
Database = @"C:\Git\DB\Test.fdb",
ServerType = FbServerType.Default,
UserID = "SYSDBA",
Password = "masterkey",
DataSource = "localhost"
}.ToString();

Debug.WriteLine(connectionString);

using (FbConnection connection = new FbConnection(connectionString))
using (FbCommand cmd = new FbCommand())
{
connection.Open();

cmd.Connection = connection;
switch (solutionType)
{
case SolutionType.Firebird3:
Firebird3Example(cmd);
break;

case SolutionType.Firebird2_5:
Firebird2_5Example(cmd);
break;

case SolutionType.FbScriptFB2_5:
FbScriptFB2_5Example(cmd);
break;
}

cmd.CommandText = @"insert into withgeneratedid(column2) values (@column2) returning id";
cmd.Parameters.AddWithValue("@column2", "some value");
cmd.Parameters.Add(new FbParameter() { Direction = System.Data.ParameterDirection.Output });
cmd.ExecuteNonQuery();

Console.WriteLine("Id:" + cmd.Parameters[1].Value);
Console.ReadLine();
}
}

private static void Firebird3Example(FbCommand cmd)
{
// Firebird 3 identity column
cmd.CommandText = @"create table withgeneratedid(
id integer generated by default as identity primary key,
column2 varchar(100)
)";
cmd.ExecuteNonQuery();
}

private static void Firebird2_5Example(FbCommand cmd)
{
// Firebird 2.5 and earlier normal primary key with trigger to generate key
// Table
cmd.CommandText = @"create table withgeneratedid(
id integer primary key,
column2 varchar(100)
)";
cmd.ExecuteNonQuery();

// Sequence
cmd.CommandText = "create sequence seq_withgeneratedid";
cmd.ExecuteNonQuery();

// Trigger
cmd.CommandText = @"create trigger withgeneratedid_bi before insert on withgeneratedid
as
begin
if (new.id is null) then new.id = next value for seq_withgeneratedid;
end";
cmd.ExecuteNonQuery();
}

private static void FbScriptFB2_5Example(FbCommand cmd)
{
string script = @"
create table withgeneratedid(
id integer primary key,
column2 varchar(100)
);

create sequence seq_withgeneratedid;

set term #;
create trigger withgeneratedid_bi before insert on withgeneratedid
as
begin
if (new.id is null) then new.id = next value for seq_withgeneratedid;
end#
set term ;#
";
FbScript fbScript = new FbScript(script);
fbScript.Parse();
FbBatchExecution exec = new FbBatchExecution(cmd.Connection);
exec.AppendSqlStatements(fbScript);
exec.Execute();
}

public enum SolutionType
{
FbScriptFB2_5,
Firebird2_5,
Firebird3
}
}
}

ASP.NET Firebird Telerik Kendo UI

April 19, 2021 23:09

ASP.NET Firebird Telerik Kendo UI (edit)

  • ASP.NET MVC
  • MediatR
  • CQRS
  • Entity Framework
  • Firebird
  • Autofac
  • AutoMapper
  • DBeaver
  • Telerik UI for ASP.NET MVC
  • DevExpress ASP.NET MVC
  • jQuery Ajax
  • ASP.NET MVC Razor views
  • Unit Testing in .NET: The Complete Guide
    • What unit tests are
    • Advantages of unit testing
    • Disadvantages and limitations
    • Unit testing best practices
    • What Mocking is
    • Mocking frameworks
    • Executing unit tests with the help of a mocking framework
    • Introduction to code coverage
    • When to choose your tooling

Kendo UI:

First Steps with Your Kendo UI for jQuery Project Guide | Getting Started | Kendo UI for jQuery | Kendo UI for jQuery (telerik.com)

jQuery Demos and Examples with HTML5/JavaScript Source Code | Kendo UI for jQuery (telerik.com)

Twitter Bootstrap and jQuery Responsive Demo | Kendo UI for jQuery (telerik.com)

Tales of Kendo UI Awesomeness: AdvancedREI (telerik.com)

Telerik UI for ASP.NET MVC:

ASP.NET MVC Introduction | Telerik UI for ASP.NET MVC

Telerik UI for ASP.NET MVC Demos

ASP.NET MVC UI Controls for Fast App Development | Telerik UI for ASP.NET MVC

Kendo UI vs UI for ASP.NET MVC

Kendo UI
http://www.telerik.com/kendo-ui/

$("#countries").kendoAutoComplete({
...
});

Telerik UI for ASP.NET MVC
http://www.telerik.com/aspnet-mvc/

@(Html.Kendo().AutoComplete()
.Name("countries")
...
)

Kendo UI vs UI for ASP.NET MVC - Telerik Blogs (HAY HAY HAY)

Difference between KendoUI Professional and Kendo UI MVC | static void main(string[] args) (wordpress.com) (HAY HAY HAY)

UI for ASP.NET MVC vs Kendo UI Complete in Kendo UI for jQuery General Discussions - Telerik Forums (HAY HAY HAY)

The combination of two different Telerik products helps level the playing field for all types of web developers: Kendo UI and UI for ASP.NET MVC. Whether you are an enterprise ASP.NET developer, a JavaScript champion or someone in between, these web development tools are flexible and can adapt to your needs.

Kendo UI may be the only JavaScript framework that you need to add to your web project.

UI for ASP.NET MVC UI suite is squarely meant for ASP.NET MVC developers like you – allowing you to leverage all the Kendo UI client-side widgets through easy MVC wrappers.

UI for ASP.NET MVC is not just MVC wrappers for Kendo UI though – it also includes framework pieces and Visual Studio goodies for the .NET developer. Using Kendo UI widgets via UI for ASP.NET MVC suite gives you the client-side UI functionality while having all the server-side comforts.

Also note that Telerik UI for ASP.NET MVC includes server-side wrappers for Kendo UI Web, Kendo UI DataViz and Kendo UI Mobile.

Directly to your questions:

  • Kendo UI Web targets primarily desktop, but it is touch-enabled and will operate properly on mobile devices as well. Specifically for mobile development with adaptive look and feel on different platforms, you can employ Kendo UI Mobile.
  • Yes, you can use MVC Razor views for mobile development. Also note that Telerik UI for ASP.NET MVC includes server-side wrappers for Kendo UI Web, Kendo UI DataViz and Kendo UI Mobile.
  • The difference between Kendo UI Complete and UI for ASP.NET MVC is that the latter incorporates ASP.NET MVC server wrappers, which allow you to define your code logic in server code and utilize features of the ASP.NET MVC framework.

Finally, note that Telerik.Web.Mvc.dll is an assembly from a discontinued product (Telerik MVC Extensions). Its successor product code, Telerik UI for ASP.NET MVC, resides in Kendo.Mvc.dll.

Regards, Sebastian
Telerik

CQRS:

Video: Intro to MediatR - Implementing CQRS and Mediator Patterns - YouTube

Video: Vertical Slice Architecture - Jimmy Bogard - YouTube

Building MVC Jimmy Style (thefreezeteam.azurewebsites.net)

CQRS (martinfowler.com)

Command Query Separation (martinfowler.com)

PDF: CQRS Documents by Greg Young (wordpress.com)

MediatR:

Thin Controllers with CQRS and MediatR (codeopinion.com)

Thin Controllers using MediatR with ASP.NET MVC | Alex Lindgren

Simplify your controllers with the Command Pattern and MediatR (jonhilton.net)

Moving from Controllers and Actions to Endpoints with MediatR | Blog (ardalis.com)

Using Scaffold-DbContext in EF Core 2.1 with Firebird database

April 17, 2021 22:03

Using Scaffold-DbContext in EF Core 2.1 with Firebird database (edit)

Currently supported by EF Core:

  • Microsoft SQL Server
  • SQLite
  • Postgres (Npgsql)
  • SQL Server Compact Edition
  • InMemory (for testing purposes)
  • MySQL
  • IBM DB2
  • Oracle
  • Firebird

Forcus on:

  • .NET Core 2.1
  • EF Core 2.1
  • Firebird Database
  • Scaffold-DbContext
  • Generate Models from Existing Database

Nugets:

  • .NET Core 2.1
  • ASP.NET Core MVC 2.1
  • Install-package EntityFrameworkCore.FirebirdSql -Version 2.1.2.2
  • Install-package Microsoft.EntityFrameworkCore -Version 2.1.14
  • Install-package Microsoft.EntityFrameworkCore.Tools -Version 2.1.14

EF 6:

  • EntityFramework (EF 6)
  • EntityFramework.SqlServerCompact (EF 6)

EF Core:

  • Microsoft.EntityFrameworkCore
  • FirebirdSql.Data.FirebirdClient
  • FirebirdSql.EntityFrameworkCore.Firebird

.NET Provider for Firebird

  • Firebird ADO.NET Data Provider
  • Microsoft SQL Server Compact Data Provider 4.0
  • More ...

How to build a Connection String?

Class: FirebirdSql.Data.FirebirdClient.FbConnectionStringBuilder

var connectionString = new FbConnectionStringBuilder
{
Database = "mydb",
DataSource = "localhost",
ServerType = FbServerType.Default,
UserID = "sysdba",
Password = "masterkey",
}.ToString();

How to use Scaffold-DbContext?

Scaffold-DbContext "character set=none;data source=localhost;initial catalog=mydb;user id=sysdba;password=masterkey;" EntityFrameworkCore.FirebirdSql -Force -OutputDir Models

Scaffold-DbContext "User=xxxx;Password=xxxx;Database=xxxx;DataSource=xxxxxx;Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;" FirebirdSql.EntityFrameworkCore.Firebird -OutputDir Models

.NET Core CSharp Project (.csproj)

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFrameworkCore.FirebirdSql" Version="2.1.2.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project> 

Next with .NET Core 3.1:

  • .NET Core 3.1
  • ASP.NET Core MVC 3.1
  • EF Core 3.1

Next with .NET Core 5.0:

  • .NET Core 5.0
  • ASP.NET Core MVC 5.0
  • EF Core 5.0

References:

https://github.com/cincuranet/FirebirdSql.Data.FirebirdClient

https://github.com/ralmsdeveloper/EntityFrameworkCore.FirebirdSQL (HAY HAY HAY)

https://www.programmersought.com/article/6109272731/ (HAY HAY HAY)

https://hoanguyenit.com/create-database-using-code-first-in-aspnet-core-21.html

https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro?view=aspnetcore-5.0

http://www.binaryintellect.net/articles/87446533-54b3-41ad-bea9-994091686a55.aspx

https://docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-entityframework-core-example.html

Firebird

April 9, 2021 16:30

Firebird (edit)

Raw SQL Queries - EF6 | Microsoft Docs

Execute Raw SQL Query in Entity Framework 6 (entityframeworktutorial.net)

Executing Raw SQL Queries using Entity Framework Core | Learn Entity Framework Core

EntityFramework.Docs/raw-sql.md at main · dotnet/EntityFramework.Docs · GitHub

Executing Raw SQL Queries using Entity Framework | BinaryIntellect Knowledge Base

Sample/Program.cs at master · kowill/Sample · GitHub

Categories

Recent posts