main
syneffort 2 years ago
parent 7695afe01c
commit 52eb1e7df7
  1. 31
      MSSQLServer_Console/MSSQLServer_Console.sln
  2. 6
      MSSQLServer_Console/MSSQLServer_Console/App.config
  3. 58
      MSSQLServer_Console/MSSQLServer_Console/MSSQLServer_Console.csproj
  4. 59
      MSSQLServer_Console/MSSQLServer_Console/Program.cs
  5. 36
      MSSQLServer_Console/MSSQLServer_Console/Properties/AssemblyInfo.cs
  6. 214
      MSSQLServer_Console/PSqlSeverWrapper/PSqlServer.cs
  7. 51
      MSSQLServer_Console/PSqlSeverWrapper/PSqlServerWrapper.csproj
  8. 36
      MSSQLServer_Console/PSqlSeverWrapper/Properties/AssemblyInfo.cs

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32630.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSSQLServer_Console", "MSSQLServer_Console\MSSQLServer_Console.csproj", "{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSqlServerWrapper", "PSqlSeverWrapper\PSqlServerWrapper.csproj", "{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}.Release|Any CPU.Build.0 = Release|Any CPU
{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {81236D94-A83B-4C4D-851B-6AAC290B7821}
EndGlobalSection
EndGlobal

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{88D9ABEA-C8C1-45B7-86BF-A0A04124B00B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MSSQLServer_Console</RootNamespace>
<AssemblyName>MSSQLServer_Console</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PSqlSeverWrapper\PSqlServerWrapper.csproj">
<Project>{34e74a48-f0b4-4f7f-9827-11aa4e0052d0}</Project>
<Name>PSqlServerWrapper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,59 @@
using PSqlSeverWrapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MSSQLServer_Console
{
class Program
{
static void Main(string[] args)
{
PSqlServer.ServerName = "peacecloud.synology.me,21433";
PSqlServer.DatabaseName = "Study";
PSqlServer.UserId = "study";
PSqlServer.Password = "Study123$";
//PSqlServer.ExecuteQuery(
//@"CREATE TABLE member (
// name VARCHAR(50),
// age INT,
// guid VARCHAR(50) NOT NULL PRIMARY KEY
//);");
//Console.WriteLine("table create.");
Random rnd = new Random();
//using (SqlConnection conn = PSqlServer.Connection)
//{
// conn.Open();
// for (int i = 0; i < 2000; i++)
// {
// string guid = Guid.NewGuid().ToString();
// int age = rnd.Next(1, 100);
// string name = $"Robo#{i + 1}";
// string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
// PSqlServer.ExecuteQuery(conn, insertQry);
// }
// conn.Close();
//}
string[] queries = new string[2000];
for (int i = 0; i < 2000; i++)
{
string guid = Guid.NewGuid().ToString();
int age = rnd.Next(1, 100);
string name = $"Robo#{i + 1}";
queries[i] = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
}
PSqlServer.ExecuteQuery(queries);
Console.WriteLine("finish");
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("MSSQLServer_Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MSSQLServer_Console")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("88d9abea-c8c1-45b7-86bf-a0a04124b00b")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSqlSeverWrapper
{
public class PSqlServer
{
public static string ServerName { get; set; }
public static string DatabaseName { get; set; }
public static string UserId { private get; set; }
public static string Password { private get; set; }
public static int MinPoolSize { get; set; } = 20;
public static int MaxPoolSize { get; set; } = 100;
public static int TimeOut { get; set; } = 15;
private static string ConnString
{
get { return $"server={ServerName}; database={DatabaseName}; uid={UserId}; pwd={Password}; min pool size = {MinPoolSize}; max pool size = {MaxPoolSize}; connection timeout = {TimeOut};"; }
}
public static SqlConnection Connection
{
get
{
if (!CheckBasicInfo())
throw new ArgumentException("Invalid connection info");
try
{
return new SqlConnection(ConnString);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
}
public static void ExecuteQuery(string query)
{
try
{
using (SqlConnection conn = Connection)
{
conn.Open();
SqlCommand command = new SqlCommand(query, conn);
command.ExecuteNonQuery();
Connection.Close();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static void ExecuteQuery(SqlConnection openedConn, string query)
{
try
{
SqlCommand command = new SqlCommand(query, openedConn);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static void ExecuteQueryAsync(SqlConnection openedConn, string query)
{
try
{
SqlCommand command = new SqlCommand(query, openedConn);
command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static void ExecuteQuery(string[] queries)
{
try
{
using (SqlConnection conn = Connection)
{
conn.Open();
ExecuteQuery(conn, "BEGIN TRAN;");
for (int i = 0; i < queries.Length; i++)
{
SqlCommand command = new SqlCommand(queries[i], conn);
command.ExecuteNonQuery();
}
ExecuteQuery(conn, "COMMIT TRAN;");
Connection.Close();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static void ExecuteQueryAsync(string query)
{
try
{
using (SqlConnection conn = Connection)
{
conn.Open();
SqlCommand command = new SqlCommand(query, conn);
command.ExecuteNonQueryAsync();
Connection.Close();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static DataSet ExecuteSelectQuery(string query)
{
try
{
using (SqlConnection conn = Connection)
{
DataSet dataSet = new DataSet();
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(query, conn);
adapter.Fill(dataSet);
Connection.Close();
return dataSet;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static DataSet ExecuteSelectQuery(SqlConnection openedConn, string query)
{
try
{
DataSet dataSet = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(query, openedConn);
adapter.Fill(dataSet);
return dataSet;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
public static SqlDataAdapter GetAdapterSelectQuery(SqlConnection openedConn, string query, bool withCommandBuilder = true)
{
try
{
SqlDataAdapter adapter = new SqlDataAdapter(query, openedConn);
if (withCommandBuilder)
{
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.DeleteCommand = builder.GetDeleteCommand();
adapter.InsertCommand = builder.GetInsertCommand();
}
return adapter;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
}
private static bool CheckBasicInfo()
{
if (string.IsNullOrEmpty(ServerName))
return false;
if (string.IsNullOrEmpty(DatabaseName))
return false;
if (string.IsNullOrEmpty(UserId))
return false;
if (string.IsNullOrEmpty(Password))
return false;
return true;
}
}
}

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{34E74A48-F0B4-4F7F-9827-11AA4E0052D0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PSqlServerWrapper</RootNamespace>
<AssemblyName>PSqlServerWrapper</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PSqlServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("PSqlSeverWrapper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PSqlSeverWrapper")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("34e74a48-f0b4-4f7f-9827-11aa4e0052d0")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading…
Cancel
Save