mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 14:37:16 +00:00
40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Data.SqlClient;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace DatabaseConnection
|
|
{
|
|
//[ComVisible(true)]
|
|
//[Guid("8bebe939-7a73-4ba3-877b-50cd2a7e4586")]
|
|
//[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
|
|
public interface bnhtradeDbInterface
|
|
{
|
|
SqlConnection Connection(string DataSource, string InitialCatalog, string UserId, string Password, bool PersistSecurityInfo = true, bool MultipleActiveResultSets = true);
|
|
}
|
|
|
|
//[ComVisible(true)]
|
|
//[Guid("b0e29c9e-d353-4d3a-83dd-5278b520af54")]
|
|
//[ClassInterface(ClassInterfaceType.None)]
|
|
////[ProgId("MyNameSpace.Criteria")]
|
|
public class bnhtradeDb : bnhtradeDbInterface
|
|
{
|
|
public SqlConnection Connection(string DataSource, string InitialCatalog, string UserId, string Password, bool PersistSecurityInfo = true, bool MultipleActiveResultSets = true)
|
|
{
|
|
if (InitialCatalog == "" || DataSource == "" || UserId == "" || Password == "")
|
|
{
|
|
throw new Exception("Insuficent info supplied for sql connection string");
|
|
}
|
|
string connString =
|
|
"Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString() + ";" +
|
|
"User ID=" + UserId + ";Password=" + Password + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString() + "";
|
|
|
|
SqlConnection sqlConn = new SqlConnection(connString);
|
|
|
|
return sqlConn;
|
|
}
|
|
}
|
|
} |