. . Assembly (dll exe) CLI PE . , , , , , .
, Embedded.Resource Project Properties, , . , , .NET.
SqlCommand SQL-. .
The following is a solution code based on managed resources. To make it work, add MySqlScripts.sql to the root file of your project and mark it as Embedded.Resource. In this implementation, the default root namespace of the project was "SqlScriptAsAResource", and this is reflected in the name of the embedded resources. Modify the file, namespace, and embedded resource names accordingly.
using System;
using System.IO;
using System.Reflection;
namespace SqlScriptAsAResource
{
class Program
{
static void Main(string[] args)
{
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream resStream = myAssembly.GetManifestResourceStream("SqlScriptAsAResource.MySqlScripts.sql");
using(StreamReader reader = new StreamReader(resStream))
{
String sqlScript = reader.ReadToEnd();
}
}
}
}
The solution based on static members is as follows:
using System;
using System.Data.SqlClient;
namespace SqlScriptAsAResource
{
internal static class SqlUtilities
{
public static readonly String SqlScriptValue = "SELECT * FROM Table1;";
public static readonly SqlCommand Commadn = new SqlCommand("SELECT * FROM Table1;");
}
}
source
share