expose sql server on public network without exposing your sql server on public network


with SQL Gateway Service

  • use System.Data.SqlClient
  • custom DB name not even exist
  • custom authentication
  • webapi as backend data provider
  • SELECT table_result FROM datasource_in_any_form

c# sample code:

var user = "anything not empty";
var pwd = "anything not empty";
var sql = "Any Text as QUERY that your webapi could respond";
var connectionString = $"data source=gateway.f5ve.cn,11433;initial catalog=f5ve;user id={user};password={pwd};";
var tables = new System.Data.DataSet();
using (var conn = new System.Data.SqlClient.SqlConnection(connectionString))
{
    var cmd = new System.Data.SqlClient.SqlCommand(sql, conn);
    var adpter = new System.Data.SqlClient.SqlDataAdapter(cmd);
    adpter.Fill(tables);
}

try it out, the result DataSet has one table like

item                            value
------------------------------------------------
Service.FrameworkDescription    .NET Core 3.1.22
Service.ProgName                SQL Server Knockoff
Service.ProgVersion             0.1.2.0
Service.Knockoff                SQLServer2016
Connection.Database             f5ve
Connection.User id              any user not empty
Connection.SqlCommand           Any Text as QUERY that your webapi could respond
Client.HostName                 LocalMachine
Client.ServerName               gateway.f5ve.cn,11433
Client.AppName                  .Net SqlClient Data Provider
Client.ProgVer                  6
Client.TDSVersion               TDS_74

with SQL Proxy Service

  • use System.Data.SqlClient / SQL Management Studio / PowerBI
  • custom DB name not even exist
  • custom authentication
  • real SQL Server as backend data provider
  • proxy SQL stream to your SQL Server in LAN

sample proxy:

var user = "anything not empty";
var pwd = "anything not empty";
var sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'";
var connectionString = $"data source=proxy.f5ve.cn,12433;initial catalog=f5ve;user id={user};password={pwd};";
(comming soon...)