-
Notifications
You must be signed in to change notification settings - Fork 1
/
MSSQLEXPDB.cs
101 lines (86 loc) · 3.17 KB
/
MSSQLEXPDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data.Common;
using System.Data.SqlServerCe;
using System.Windows;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace CheckCasher
{
class MSSQLEXPDB : SQLDB
{
SqlConnection conn = null;
//string connstr = "Datasource=" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
//"\\CheckCasher.sdf;password=";
//string connstr = "data source=owner-pc\\checkcasher;initial catalog=CheckCasher;"+
// "integrated security=SSPI;Trusted_Connection=Yes;persist security info=False";
string connstr = string.Empty;
private string getConnStr() {
string str = "data source="+ConfigurationManager.AppSettings.Get("ds");
//str = str + ";User ID=" + ConfigurationManager.AppSettings.Get("user");
//str = str + ";Password=" + ConfigurationManager.AppSettings.Get("pwd");
str = str + ";initial catalog=" + ConfigurationManager.AppSettings.Get("ic");
str = str + ";integrated security=" + ConfigurationManager.AppSettings.Get("is");
str = str + ";Trusted_Connection=" + ConfigurationManager.AppSettings.Get("tc");
str = str + ";persist security info=" + ConfigurationManager.AppSettings.Get("psi");
//MessageBox.Show(str);
//string cstr = "Data Source=67.80.82.197;database=checkcasher;Integrated Security=False;User Id=sa;Password=equat10n;Connect Timeout=0";
return str;
}
public MSSQLEXPDB()
{
connstr = getConnStr();
}
public void close()
{
conn.Close();
}
public void connect()
{
if (conn == null || conn.State == ConnectionState.Broken || conn.State == ConnectionState.Closed)
{
conn = new SqlConnection(connstr);
conn.Open();
}
}
public int ExecuteNonQuery(string sql)
{
connect();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
int res = cmd.ExecuteNonQuery();
close();
return res;
}
public DbDataReader ExecuteQuery(string sql)
{
connect();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return rdr;
}
public DbDataReader GetImage(string sql)
{
connect();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
SqlDataReader rdr = cmd.ExecuteReader();
return rdr;
}
public int UpdateImage(string sql, object data, string param)
{
connect();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.Parameters.Add(new SqlParameter(param, data));
int res = cmd.ExecuteNonQuery();
close();
return res;
}
}
}