Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectMsSql.cs
1using Microsoft.Data.SqlClient;
3using System.Threading.Tasks;
8
10{
15 {
23 public ConnectMsSql(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
24 : base(new ScriptNode[] { ConnectionString }, argumentTypes1Scalar, Start, Length, Expression)
25 {
26 }
27
37 : base(new ScriptNode[] { Host, Database }, argumentTypes2Scalar, Start, Length, Expression)
38 {
39 }
40
50 public ConnectMsSql(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
51 : base(new ScriptNode[] { ConnectionString, UserName, Password }, argumentTypes3Scalar, Start, Length, Expression)
52 {
53 }
54
65 public ConnectMsSql(ScriptNode Host, ScriptNode Database, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
66 : base(new ScriptNode[] { Host, Database, UserName, Password }, argumentTypes4Scalar, Start, Length, Expression)
67 {
68 }
69
73 public override string FunctionName => nameof(ConnectMsSql);
74
78 public override string[] DefaultArgumentNames => new string[] { "Host", "Database", "UserName", "Password" };
79
84 public override bool IsAsynchronous => true;
85
93 {
94 return this.EvaluateAsync(Arguments, Variables).Result;
95 }
96
103 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
104 {
105 string ConnectionString = ToString(Arguments[0]) ?? string.Empty;
106 SqlConnection Connection;
107
108 switch (Arguments.Length)
109 {
110 case 1:
111 default:
112 Connection = new SqlConnection(ConnectionString);
113 break;
114
115 case 2:
116 string Database = ToString(Arguments[1]) ?? string.Empty;
117
118 ConnectionString = "Data Source=" + ConnectionString + ";Initial Catalog=" + Database + ";Integrated Security=true";
119 Connection = new SqlConnection(ConnectionString);
120 break;
121 case 3:
122 string UserName = ToString(Arguments[1]) ?? string.Empty;
123 string Password = ToString(Arguments[2]) ?? string.Empty;
124 SecureString Password2 = new SecureString();
125
126 foreach (char ch in Password)
127 Password2.AppendChar(ch);
128
129 Password2.MakeReadOnly();
130 Connection = new SqlConnection(ConnectionString, new SqlCredential(UserName, Password2));
131 break;
132
133 case 4:
134 Database = ToString(Arguments[1]) ?? string.Empty;
135 UserName = ToString(Arguments[2]) ?? string.Empty;
136 Password = ToString(Arguments[3]) ?? string.Empty;
137 Password2 = new SecureString();
138
139 foreach (char ch in Password)
140 Password2.AppendChar(ch);
141
142 Password2.MakeReadOnly();
143
144 ConnectionString = "Data Source=" + ConnectionString + ";Initial Catalog=" + Database;
145 Connection = new SqlConnection(ConnectionString, new SqlCredential(UserName, Password2));
146 break;
147 }
148
149 await Connection.OpenAsync();
150
151 return new ObjectValue(new MsSqlDatabase(Connection));
152 }
153 }
154}
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:15
ConnectMsSql(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:50
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ConnectMsSql.cs:84
ConnectMsSql(ScriptNode Host, ScriptNode Database, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:65
ConnectMsSql(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:23
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: ConnectMsSql.cs:92
override string FunctionName
Name of the function
Definition: ConnectMsSql.cs:73
override string[] DefaultArgumentNames
Default Argument names
Definition: ConnectMsSql.cs:78
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
ConnectMsSql(ScriptNode Host, ScriptNode Database, int Start, int Length, Expression Expression)
Creates a connection to an external MS SQL database.
Definition: ConnectMsSql.cs:36
Manages a Microsoft SQL Server connection
Class managing a script expression.
Definition: Expression.cs:41
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
static readonly ArgumentType[] argumentTypes4Scalar
Four scalar parameters.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21