AbstractDBConnection.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. //
  2. // System.Data.Common.AbstractDBConnection
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. // Boris Kirzner <[email protected]>
  7. //
  8. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Data;
  31. using System.Data.ProviderBase;
  32. using System.Data.Configuration;
  33. using System.Configuration;
  34. using System.Collections;
  35. using System.Collections.Specialized;
  36. using System.Text;
  37. using System.Text.RegularExpressions;
  38. using java.sql;
  39. using javax.sql;
  40. using javax.naming;
  41. // can not use java.util here - it manes ArrayList an ambiguous reference
  42. namespace System.Data.Common
  43. {
  44. public abstract class AbstractDBConnection : DbConnection
  45. {
  46. #region ObjectNamesHelper
  47. private sealed class ObjectNamesHelper
  48. {
  49. //static readonly Regex NameOrder = new Regex(@"^\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  50. static readonly Regex NameOrder = new Regex(@"^((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  51. //static readonly Regex SchemaNameOrder = new Regex(@"^\s*((\[(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  52. static readonly Regex SchemaNameOrder = new Regex(@"^((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  53. //static readonly Regex CatalogSchemaNameOrder = new Regex(@"^\s*((\[\s*(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  54. //static readonly Regex CatalogSchemaNameOrder = new Regex(@"^\s*((\[\s*(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<SCHEMA>(\s*[^\]\s])+)\s*\])|(?<SCHEMA>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  55. static readonly Regex CatalogSchemaNameOrder = new Regex(@"^((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  56. //static readonly Regex CatalogNameOrder = new Regex(@"^\s*((\[(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  57. //static readonly Regex CatalogNameOrder = new Regex(@"^\s*((\[(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  58. static readonly Regex CatalogNameOrder = new Regex(@"^((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  59. //static readonly Regex SchemaCatalogNameOrder = new Regex(@"^\s*((\[\s*(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  60. //static readonly Regex SchemaCatalogNameOrder = new Regex(@"^\s*((\[\s*(?<SCHEMA>(\s*[^\]\s])+)\s*\])|(?<SCHEMA>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  61. static readonly Regex SchemaCatalogNameOrder = new Regex(@"^((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  62. internal static ObjectNameResolver[] GetSyntaxPatterns(AbstractDBConnection connection)
  63. {
  64. ArrayList collection = new ArrayList();
  65. collection.Add(new ObjectNameResolver(NameOrder));
  66. ObjectNameResolversCollection basic = (ObjectNameResolversCollection)ConfigurationSettings.GetConfig("system.data/objectnameresolution");
  67. DatabaseMetaData metaData = connection.JdbcConnection.getMetaData();
  68. string productName = metaData.getDatabaseProductName();
  69. foreach(ObjectNameResolver nameResolver in basic) {
  70. if (productName.IndexOf(nameResolver.DbName) != -1) {
  71. collection.Add(nameResolver);
  72. }
  73. }
  74. //defaults
  75. if (metaData.isCatalogAtStart()) {
  76. collection.Add(new ObjectNameResolver(SchemaNameOrder));
  77. collection.Add(new ObjectNameResolver(CatalogNameOrder));
  78. collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
  79. collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
  80. }
  81. else {
  82. collection.Add(new ObjectNameResolver(CatalogNameOrder));
  83. collection.Add(new ObjectNameResolver(SchemaNameOrder));
  84. collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
  85. collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
  86. }
  87. return (ObjectNameResolver[])collection.ToArray(typeof(ObjectNameResolver));
  88. }
  89. }
  90. #endregion // ObjectNamesHelper
  91. #region ConnectionStringHelper
  92. internal sealed class ConnectionStringHelper
  93. {
  94. internal static string FindValue(NameValueCollection collection, string[] keys)
  95. {
  96. if (collection == null || keys == null || keys.Length == 0) {
  97. return String.Empty;
  98. }
  99. for(int i=0; i < keys.Length; i++) {
  100. string value = FindValue(collection,keys[i]);
  101. if (!String.Empty.Equals(value)) {
  102. return value;
  103. }
  104. }
  105. return String.Empty;
  106. }
  107. internal static string FindValue(NameValueCollection collection, string key)
  108. {
  109. if (collection == null) {
  110. return String.Empty;
  111. }
  112. string value = collection[key];
  113. return (value != null) ? value : String.Empty;
  114. }
  115. internal static void UpdateValue(NameValueCollection collection,string[] keys,string value)
  116. {
  117. for(int i=0; i < keys.Length; i++) {
  118. if (collection[keys[i]] != null) {
  119. collection[keys[i]] = value;
  120. }
  121. }
  122. }
  123. internal static void AddValue(NameValueCollection collection,string[] keys,string value)
  124. {
  125. for(int i=0; i < keys.Length; i++) {
  126. collection[keys[i]] = value;
  127. }
  128. }
  129. /**
  130. * Parses connection string and builds NameValueCollection
  131. * for all keys.
  132. */
  133. internal static NameValueCollection BuildUserParameters (string connectionString)
  134. {
  135. NameValueCollection userParameters = new NameValueCollection();
  136. if (connectionString == null || connectionString.Length == 0) {
  137. return userParameters;
  138. }
  139. connectionString += ";";
  140. bool inQuote = false;
  141. bool inDQuote = false;
  142. bool inName = true;
  143. string name = String.Empty;
  144. string value = String.Empty;
  145. StringBuilder sb = new StringBuilder ();
  146. for (int i = 0; i < connectionString.Length; i += 1) {
  147. char c = connectionString [i];
  148. char peek;
  149. if (i == connectionString.Length - 1)
  150. peek = '\0';
  151. else
  152. peek = connectionString [i + 1];
  153. switch (c) {
  154. case '\'':
  155. if (inDQuote)
  156. sb.Append (c);
  157. else if (peek.Equals(c)) {
  158. sb.Append(c);
  159. i += 1;
  160. }
  161. else
  162. inQuote = !inQuote;
  163. break;
  164. case '"':
  165. if (inQuote)
  166. sb.Append(c);
  167. else if (peek.Equals(c)) {
  168. sb.Append(c);
  169. i += 1;
  170. }
  171. else
  172. inDQuote = !inDQuote;
  173. break;
  174. case ';':
  175. if (inDQuote || inQuote)
  176. sb.Append(c);
  177. else {
  178. if (name != String.Empty && name != null) {
  179. value = sb.ToString();
  180. userParameters [name.Trim()] = value.Trim();
  181. }
  182. inName = true;
  183. name = String.Empty;
  184. value = String.Empty;
  185. sb = new StringBuilder();
  186. }
  187. break;
  188. case '=':
  189. if (inDQuote || inQuote || !inName)
  190. sb.Append (c);
  191. else if (peek.Equals(c)) {
  192. sb.Append (c);
  193. i += 1;
  194. }
  195. else {
  196. name = sb.ToString();
  197. sb = new StringBuilder();
  198. inName = false;
  199. }
  200. break;
  201. case ' ':
  202. if (inQuote || inDQuote)
  203. sb.Append(c);
  204. else if (sb.Length > 0 && !peek.Equals(';'))
  205. sb.Append(c);
  206. break;
  207. default:
  208. sb.Append(c);
  209. break;
  210. }
  211. }
  212. return userParameters;
  213. }
  214. }
  215. #endregion // ConnectionStringHelper
  216. #region DataSourceCache
  217. private sealed class DataSourceCache : AbstractDbMetaDataCache
  218. {
  219. internal DataSource GetDataSource(string dataSourceName,string namingProviderUrl,string namingFactoryInitial)
  220. {
  221. Hashtable cache = Cache;
  222. DataSource ds = cache[dataSourceName] as DataSource;
  223. if (ds != null) {
  224. return ds;
  225. }
  226. Context ctx = null;
  227. java.util.Properties properties = new java.util.Properties();
  228. if ((namingProviderUrl != null) && (namingProviderUrl.Length > 0)) {
  229. properties.put("java.naming.provider.url",namingProviderUrl);
  230. }
  231. if ((namingFactoryInitial != null) && (namingFactoryInitial.Length > 0)) {
  232. properties.put("java.naming.factory.initial",namingFactoryInitial);
  233. }
  234. ctx = new InitialContext(properties);
  235. try {
  236. ds = (DataSource)ctx.lookup(dataSourceName);
  237. }
  238. catch(javax.naming.NameNotFoundException e) {
  239. // possible that is a Tomcat bug,
  240. // so try to lookup for jndi datasource with "java:comp/env/" appended
  241. ds = (DataSource)ctx.lookup("java:comp/env/" + dataSourceName);
  242. }
  243. cache[dataSourceName] = ds;
  244. return ds;
  245. }
  246. }
  247. #endregion // DatasourceCache
  248. #region Declarations
  249. protected internal enum JDBC_MODE { NONE, DATA_SOURCE_MODE, JDBC_DRIVER_MODE, PROVIDER_MODE }
  250. protected internal enum PROVIDER_TYPE { NONE, SQLOLEDB, MSDAORA, IBMDADB2 }
  251. #endregion // Declarations
  252. #region Fields
  253. private static DataSourceCache _dataSourceCache = new DataSourceCache();
  254. private const int DEFAULT_TIMEOUT = 15;
  255. private Connection _jdbcConnnection;
  256. private ConnectionState _internalState;
  257. private object _internalStateSync = new object();
  258. private NameValueCollection _userParameters;
  259. protected string _connectionString = String.Empty;
  260. protected string _jdbcUrl;
  261. private ArrayList _referencedObjects = new ArrayList();
  262. private ObjectNameResolver[] _syntaxPatterns;
  263. #endregion // Fields
  264. #region Constructors
  265. public AbstractDBConnection(string connectionString)
  266. {
  267. _connectionString = connectionString;
  268. InitializeSkippedUserParameters();
  269. }
  270. #endregion // Constructors
  271. #region Properties
  272. public override String ConnectionString
  273. {
  274. get { return _connectionString; }
  275. set {
  276. if (IsOpened) {
  277. throw ExceptionHelper.NotAllowedWhileConnectionOpen("ConnectionString",_internalState);
  278. }
  279. _connectionString = value;
  280. _userParameters = null;
  281. _jdbcUrl = null;
  282. }
  283. }
  284. public override int ConnectionTimeout
  285. {
  286. get {
  287. string timeoutStr = ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_TIMEOUT"));
  288. if (!String.Empty.Equals(timeoutStr)) {
  289. try {
  290. return Convert.ToInt32(timeoutStr);
  291. }
  292. catch(FormatException e) {
  293. throw ExceptionHelper.InvalidValueForKey("connect timeout");
  294. }
  295. catch (OverflowException e) {
  296. throw ExceptionHelper.InvalidValueForKey("connect timeout");
  297. }
  298. }
  299. return DEFAULT_TIMEOUT;
  300. }
  301. }
  302. public override String Database
  303. {
  304. get { return ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_DATABASE")); }
  305. }
  306. public override ConnectionState State
  307. {
  308. get {
  309. try {
  310. if ((JdbcConnection == null) || JdbcConnection.isClosed()) {
  311. // jdbc connection not initialized or closed
  312. if (_internalState == ConnectionState.Closed ) {
  313. return ConnectionState.Closed;
  314. }
  315. }
  316. else {
  317. // jdbc connection is opened
  318. if ((_internalState & ConnectionState.Open) != 0) {
  319. return ConnectionState.Open;
  320. }
  321. }
  322. return ConnectionState.Broken;
  323. }
  324. catch (SQLException) {
  325. return ConnectionState.Broken;
  326. }
  327. }
  328. }
  329. internal bool IsExecuting
  330. {
  331. get {
  332. return ((_internalState & ConnectionState.Executing) != 0);
  333. }
  334. set {
  335. lock(_internalStateSync) {
  336. // to switch to executing, the connection must be in opened
  337. if (value) {
  338. if (_internalState != ConnectionState.Open) {
  339. if (IsFetching) {
  340. throw ExceptionHelper.OpenedReaderExists();
  341. }
  342. throw ExceptionHelper.OpenConnectionRequired("",_internalState);
  343. }
  344. _internalState |= ConnectionState.Executing;
  345. }
  346. else {
  347. if (!IsExecuting) {
  348. throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Executing.ToString() + " while in state " + _internalState.ToString());
  349. }
  350. _internalState &= ~ConnectionState.Executing;
  351. }
  352. }
  353. }
  354. }
  355. internal bool IsFetching
  356. {
  357. get {
  358. return ((_internalState & ConnectionState.Fetching) != 0);
  359. }
  360. set {
  361. lock(_internalStateSync) {
  362. if (value) {
  363. // to switch to fetching connection must be in opened, executing
  364. if (((_internalState & ConnectionState.Open) == 0) || ((_internalState & ConnectionState.Executing) == 0)) {
  365. throw ExceptionHelper.OpenConnectionRequired("",_internalState);
  366. }
  367. _internalState |= ConnectionState.Fetching;
  368. }
  369. else {
  370. if (!IsFetching) {
  371. throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Fetching.ToString() + " while in state " + _internalState.ToString());
  372. }
  373. _internalState &= ~ConnectionState.Fetching;
  374. }
  375. }
  376. }
  377. }
  378. internal bool IsOpened
  379. {
  380. get {
  381. return ((_internalState & ConnectionState.Open) != 0);
  382. }
  383. set {
  384. lock(_internalStateSync) {
  385. if (value) {
  386. // only connecting connection can be opened
  387. if ((_internalState != ConnectionState.Connecting)) {
  388. throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
  389. }
  390. _internalState |= ConnectionState.Open;
  391. }
  392. else {
  393. if (!IsOpened) {
  394. throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Open.ToString() + " while in state " + _internalState.ToString());
  395. }
  396. _internalState &= ~ConnectionState.Open;
  397. }
  398. }
  399. }
  400. }
  401. internal bool IsConnecting
  402. {
  403. get {
  404. return ((_internalState & ConnectionState.Connecting) != 0);
  405. }
  406. set {
  407. lock(_internalStateSync) {
  408. if (value) {
  409. // to switch to connecting conection must be in closed or in opened
  410. if ((_internalState != ConnectionState.Closed) && (_internalState != ConnectionState.Open)) {
  411. throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
  412. }
  413. _internalState |= ConnectionState.Connecting;
  414. }
  415. else {
  416. if (!IsConnecting) {
  417. throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Connecting.ToString() + " while in state " + _internalState.ToString());
  418. }
  419. _internalState &= ~ConnectionState.Connecting;
  420. }
  421. }
  422. }
  423. }
  424. protected virtual PROVIDER_TYPE ProviderType
  425. {
  426. get {
  427. if (JdbcMode != JDBC_MODE.PROVIDER_MODE) {
  428. return PROVIDER_TYPE.NONE;
  429. }
  430. string providerStr = ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_PROVIDER")).ToUpper();
  431. if (providerStr.StartsWith("SQLOLEDB")) {
  432. return PROVIDER_TYPE.SQLOLEDB;
  433. }
  434. else if (providerStr.StartsWith("MSDAORA")) {
  435. return PROVIDER_TYPE.MSDAORA;
  436. }
  437. else if (providerStr.StartsWith("IBMDADB2")) {
  438. return PROVIDER_TYPE.IBMDADB2;
  439. }
  440. return PROVIDER_TYPE.NONE;
  441. }
  442. }
  443. protected internal virtual JDBC_MODE JdbcMode
  444. {
  445. get {
  446. string[] conJndiNameStr = StringManager.GetStringArray("CON_JNDI_NAME");
  447. if ( !String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,conJndiNameStr))) {
  448. return JDBC_MODE.DATA_SOURCE_MODE;
  449. }
  450. string[] jdbcDriverStr = StringManager.GetStringArray("JDBC_DRIVER");
  451. string[] jdbcUrlStr = StringManager.GetStringArray("JDBC_URL");
  452. bool jdbcDriverSpecified = !String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,jdbcDriverStr));
  453. bool jdbcUrlSpecified = !String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,jdbcUrlStr));
  454. if (jdbcDriverSpecified && jdbcUrlSpecified) {
  455. return JDBC_MODE.JDBC_DRIVER_MODE;
  456. }
  457. string[] providerStr = StringManager.GetStringArray("CON_PROVIDER");
  458. if (!String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,providerStr))) {
  459. return JDBC_MODE.PROVIDER_MODE;
  460. }
  461. return JDBC_MODE.NONE;
  462. }
  463. }
  464. protected virtual string JdbcDriverName
  465. {
  466. get { return String.Empty; }
  467. }
  468. protected abstract DbStringManager StringManager
  469. {
  470. get;
  471. }
  472. protected virtual string ServerName
  473. {
  474. get { return DataSource; }
  475. }
  476. protected virtual string CatalogName
  477. {
  478. get { return Database; }
  479. }
  480. protected virtual string Port
  481. {
  482. get {
  483. string port = ConnectionStringHelper.FindValue(UserParameters, StringManager.GetStringArray("CON_PORT"));
  484. switch (ProviderType) {
  485. case PROVIDER_TYPE.SQLOLEDB :
  486. if (String.Empty.Equals(port)) {
  487. // if needed - resolve MSSQL port
  488. // FIXME : decide about behaviour in the case all the timeout spent on port resolution
  489. //long start = DateTime.Now.Ticks;
  490. port = DbPortResolver.getMSSqlPort(DataSource,InstanceName,ConnectionTimeout).ToString();
  491. //long end = DateTime.Now.Ticks;
  492. //if( (end - start) < ConnectionTimeout*1000000) {
  493. //timeout -= (int)(end - start)/1000000;
  494. //}
  495. }
  496. // todo : what should we do if all the timeout spent on port resolution ?
  497. if ("-1".Equals(port)) {
  498. string message = String.Format ("Unable to retrieve the port number for {0} using UDP on port 1434. Please see your network administrator to solve this problem or add the port number of your SQL server instance to your connection string (i.e. port=1681).",ServerName);
  499. Exception e = CreateException (message);
  500. throw e;
  501. }
  502. ConnectionStringHelper.AddValue(UserParameters,StringManager.GetStringArray("CON_PORT"),port);
  503. break;
  504. }
  505. return port;
  506. }
  507. }
  508. public override string DataSource
  509. {
  510. get {
  511. string dataSource = ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_DATA_SOURCE"));
  512. if (ProviderType == PROVIDER_TYPE.SQLOLEDB) {
  513. int instanceIdx;
  514. if ((instanceIdx = dataSource.IndexOf("\\")) != -1) {
  515. // throw out named instance name
  516. dataSource = dataSource.Substring(0,instanceIdx);
  517. }
  518. if (dataSource != null && dataSource.StartsWith("(") && dataSource.EndsWith(")")) {
  519. dataSource = dataSource.Substring(1,dataSource.Length - 2);
  520. }
  521. if(String.Empty.Equals(dataSource) || (String.Compare("local",dataSource,true) == 0)) {
  522. dataSource = "localhost";
  523. }
  524. }
  525. return dataSource;
  526. }
  527. }
  528. protected virtual string InstanceName
  529. {
  530. get {
  531. string dataSource = ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_DATA_SOURCE"));
  532. string instanceName = String.Empty;
  533. if (ProviderType == PROVIDER_TYPE.SQLOLEDB) {
  534. int instanceIdx;
  535. if ((instanceIdx = dataSource.IndexOf("\\")) == -1) {
  536. // no named instance specified - use a default name
  537. instanceName = StringManager.GetString("SQL_DEFAULT_INSTANCE_NAME");
  538. }
  539. else {
  540. // get named instance name
  541. instanceName = dataSource.Substring(instanceIdx + 1);
  542. }
  543. }
  544. return instanceName;
  545. }
  546. }
  547. protected virtual string User
  548. {
  549. get { return ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_USER_ID")); }
  550. }
  551. protected virtual string Password
  552. {
  553. get { return ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_PASSWORD")); }
  554. }
  555. protected NameValueCollection UserParameters
  556. {
  557. get {
  558. if (_userParameters == null) {
  559. _userParameters = ConnectionStringHelper.BuildUserParameters(ConnectionString);
  560. }
  561. return _userParameters;
  562. }
  563. }
  564. internal String JdbcUrl
  565. {
  566. get {
  567. if ( UserParameters == null) {
  568. return String.Empty;
  569. }
  570. if (_jdbcUrl == null) {
  571. _jdbcUrl = BuildJdbcUrl();
  572. }
  573. return _jdbcUrl;
  574. }
  575. }
  576. internal ConnectionState InternalState
  577. {
  578. get { return _internalState; }
  579. }
  580. protected internal Connection JdbcConnection
  581. {
  582. get { return _jdbcConnnection; }
  583. set { _jdbcConnnection = value; }
  584. }
  585. protected virtual string[] ResourceIgnoredKeys
  586. {
  587. get { return new string[0]; }
  588. }
  589. protected virtual Hashtable SkippedUserParameters
  590. {
  591. get { return new Hashtable(new CaseInsensitiveHashCodeProvider(),new CaseInsensitiveComparer()); }
  592. }
  593. internal ObjectNameResolver[] SyntaxPatterns
  594. {
  595. get {
  596. if (_syntaxPatterns == null) {
  597. _syntaxPatterns = ObjectNamesHelper.GetSyntaxPatterns(this);
  598. }
  599. return _syntaxPatterns;
  600. }
  601. }
  602. #endregion // Properties
  603. #region Methods
  604. // since WS also does not permits dynamically change of login timeout and tomcat does no implements - do not do it at all
  605. //ds.setLoginTimeout(ConnectionTimeout);
  606. internal abstract void OnSqlWarning(SQLWarning warning);
  607. internal abstract void OnStateChanged(ConnectionState orig, ConnectionState current);
  608. protected abstract SystemException CreateException(SQLException e);
  609. protected abstract SystemException CreateException(string message);
  610. public override void Close()
  611. {
  612. try {
  613. ClearReferences();
  614. if (JdbcConnection != null && !JdbcConnection.isClosed()) {
  615. JdbcConnection.close();
  616. }
  617. }
  618. catch (SQLException e) {
  619. // suppress exception
  620. JdbcConnection = null;
  621. #if DEBUG
  622. Console.WriteLine("Exception catched at Conection.Close() : {0}\n{1}\n{2}",e.GetType().FullName,e.Message,e.StackTrace);
  623. #endif
  624. }
  625. catch (Exception e) {
  626. // suppress exception
  627. JdbcConnection = null;
  628. #if DEBUG
  629. Console.WriteLine("Exception catched at Conection.Close() : {0}\n{1}\n{2}",e.GetType().FullName,e.Message,e.StackTrace);
  630. #endif
  631. }
  632. finally {
  633. lock(_internalStateSync) {
  634. _internalState = ConnectionState.Closed;
  635. }
  636. }
  637. }
  638. protected internal virtual void CopyTo(AbstractDBConnection target)
  639. {
  640. target._connectionString = _connectionString;
  641. }
  642. internal protected virtual void OnSqlException(SQLException exp)
  643. {
  644. throw CreateException(exp);
  645. }
  646. internal void AddReference(object referencedObject)
  647. { lock(_referencedObjects.SyncRoot) {
  648. _referencedObjects.Add(new WeakReference(referencedObject));
  649. }
  650. }
  651. internal void RemoveReference(object referencedObject)
  652. {
  653. lock(_referencedObjects.SyncRoot) {
  654. for(int i = 0; i < _referencedObjects.Count; i++) {
  655. WeakReference wr = (WeakReference) _referencedObjects[i];
  656. if (wr.IsAlive && (wr.Target == referencedObject)) {
  657. _referencedObjects.RemoveAt(i);
  658. }
  659. }
  660. }
  661. }
  662. private void ClearReferences()
  663. {
  664. ArrayList oldList = _referencedObjects;
  665. _referencedObjects = new ArrayList();
  666. for(int i = 0; i < oldList.Count; i++) {
  667. WeakReference wr = (WeakReference) oldList[i];
  668. if (wr.IsAlive) {
  669. ClearReference(wr.Target);
  670. }
  671. }
  672. }
  673. private void ClearReference(object referencedObject)
  674. {
  675. try {
  676. if (referencedObject is AbstractDbCommand) {
  677. ((AbstractDbCommand)referencedObject).CloseInternal();
  678. }
  679. else if (referencedObject is AbstractDataReader) {
  680. ((AbstractDataReader)referencedObject).CloseInternal();
  681. }
  682. }
  683. catch (SQLException) {
  684. // suppress exception since it's possible that command or reader are in inconsistent state
  685. }
  686. }
  687. public override void Open()
  688. {
  689. if (_connectionString == null || _connectionString.Length == 0) {
  690. throw ExceptionHelper.ConnectionStringNotInitialized();
  691. }
  692. IsConnecting = true;
  693. try {
  694. if (JdbcConnection != null && !JdbcConnection.isClosed()) {
  695. throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
  696. }
  697. switch(JdbcMode) {
  698. case JDBC_MODE.DATA_SOURCE_MODE :
  699. JdbcConnection = GetConnectionFromDataSource();
  700. break;
  701. case JDBC_MODE.JDBC_DRIVER_MODE:
  702. JdbcConnection = GetConnectionFromJdbcDriver();
  703. break;
  704. case JDBC_MODE.PROVIDER_MODE :
  705. JdbcConnection = GetConnectionFromProvider();
  706. break;
  707. }
  708. IsOpened = true;
  709. OnStateChanged(ConnectionState.Closed, ConnectionState.Open);
  710. }
  711. catch (SQLWarning warning) {
  712. OnSqlWarning(warning);
  713. }
  714. catch (SQLException exp) {
  715. OnSqlException(exp);
  716. }
  717. finally {
  718. IsConnecting = false;
  719. }
  720. }
  721. public override void ChangeDatabase(String database)
  722. {
  723. IsConnecting = true;
  724. try {
  725. ClearReferences();
  726. Connection con = JdbcConnection;
  727. con.setCatalog(database);
  728. ConnectionStringHelper.UpdateValue(UserParameters,StringManager.GetStringArray("CON_DATABASE"),database);
  729. }
  730. catch (SQLWarning warning) {
  731. OnSqlWarning(warning);
  732. }
  733. catch (SQLException exp) {
  734. throw CreateException(exp);
  735. }
  736. finally {
  737. IsConnecting = false;
  738. }
  739. }
  740. public override string ServerVersion {
  741. get {
  742. // only if the driver support this methods
  743. try {
  744. if (JdbcConnection == null)
  745. return String.Empty;
  746. DatabaseMetaData metaData = JdbcConnection.getMetaData();
  747. return metaData.getDatabaseProductVersion();
  748. }
  749. catch (SQLException exp) {
  750. throw CreateException(exp);
  751. }
  752. }
  753. }
  754. internal string JdbcProvider {
  755. get {
  756. // only if the driver support this methods
  757. try {
  758. if (JdbcConnection == null)
  759. return String.Empty;
  760. DatabaseMetaData metaData = JdbcConnection.getMetaData();
  761. return metaData.getDriverName() + " " + metaData.getDriverVersion();
  762. }
  763. catch (SQLException exp) {
  764. return String.Empty; //suppress
  765. }
  766. }
  767. }
  768. protected override void Dispose(bool disposing)
  769. {
  770. if (disposing) {
  771. try {
  772. if (JdbcConnection != null && !JdbcConnection.isClosed()) {
  773. JdbcConnection.close();
  774. }
  775. JdbcConnection = null;
  776. }
  777. catch (java.sql.SQLException exp) {
  778. throw CreateException(exp);
  779. }
  780. }
  781. base.Dispose(disposing);
  782. }
  783. protected internal virtual void ValidateConnectionString(string connectionString)
  784. {
  785. JDBC_MODE currentJdbcMode = JdbcMode;
  786. if (currentJdbcMode == JDBC_MODE.NONE) {
  787. string[] jdbcDriverStr = StringManager.GetStringArray("JDBC_DRIVER");
  788. string[] jdbcUrlStr = StringManager.GetStringArray("JDBC_URL");
  789. bool jdbcDriverSpecified = !String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,jdbcDriverStr));
  790. bool jdbcUrlSpecified = !String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,jdbcUrlStr));
  791. if (jdbcDriverSpecified ^ jdbcUrlSpecified) {
  792. throw new ArgumentException("Invalid format of connection string. If you want to use third-party JDBC driver, the format is: \"JdbcDriverClassName=<jdbc driver class name>;JdbcURL=<jdbc url>\"");
  793. }
  794. }
  795. }
  796. protected virtual string BuildJdbcUrl()
  797. {
  798. switch (JdbcMode) {
  799. case JDBC_MODE.JDBC_DRIVER_MODE :
  800. return ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("JDBC_URL"));
  801. default :
  802. return String.Empty;
  803. }
  804. }
  805. protected java.util.Properties BuildProperties()
  806. {
  807. java.util.Properties properties = new java.util.Properties();
  808. string user = User;
  809. if (user != null && user.Length > 0)
  810. properties.put("user", user);
  811. string password = Password;
  812. if (user != null && user.Length > 0)
  813. properties.put("password", password);
  814. string[] userKeys = UserParameters.AllKeys;
  815. for(int i=0; i < userKeys.Length; i++) {
  816. string userKey = userKeys[i];
  817. string userParameter = UserParameters[userKey];
  818. if (!SkipUserParameter(userKey)) {
  819. properties.put(userKey,userParameter);
  820. }
  821. }
  822. return properties;
  823. }
  824. protected virtual bool SkipUserParameter(string parameterName)
  825. {
  826. if (SkippedUserParameters.Count == 0) {
  827. // skipped parameters not initialized - skip all
  828. return true;
  829. }
  830. return SkippedUserParameters.Contains(parameterName);
  831. }
  832. protected virtual void InitializeSkippedUserParameters()
  833. {
  834. if (SkippedUserParameters.Count > 0) {
  835. return;
  836. }
  837. for(int i=0; i < ResourceIgnoredKeys.Length; i++) {
  838. string[] userKeys = StringManager.GetStringArray(ResourceIgnoredKeys[i]);
  839. for(int j=0; j < userKeys.Length; j++) {
  840. SkippedUserParameters.Add(userKeys[j],userKeys[j]);
  841. }
  842. }
  843. }
  844. internal void ValidateBeginTransaction()
  845. {
  846. if (State != ConnectionState.Open) {
  847. throw new InvalidOperationException(String.Format("{0} requires an open and available Connection. The connection's current state is {1}.", new object[] {"BeginTransaction", State}));
  848. }
  849. if (!JdbcConnection.getAutoCommit()) {
  850. throw new System.InvalidOperationException("Parallel transactions are not supported.");
  851. }
  852. }
  853. internal virtual Connection GetConnectionFromProvider()
  854. {
  855. ActivateJdbcDriver(JdbcDriverName);
  856. DriverManager.setLoginTimeout(ConnectionTimeout);
  857. java.util.Properties properties = BuildProperties();
  858. return DriverManager.getConnection (JdbcUrl, properties);
  859. }
  860. internal Connection GetConnectionFromDataSource()
  861. {
  862. string dataSourceJndi = ConnectionStringHelper.FindValue(UserParameters, StringManager.GetStringArray("CON_JNDI_NAME"));
  863. string namingProviderUrl = ConnectionStringHelper.FindValue(UserParameters, StringManager.GetStringArray("CON_JNDI_PROVIDER"));
  864. string namingFactoryInitial = ConnectionStringHelper.FindValue(UserParameters, StringManager.GetStringArray("CON_JNDI_FACTORY"));
  865. DataSource ds = _dataSourceCache.GetDataSource(dataSourceJndi,namingProviderUrl,namingFactoryInitial);
  866. try {
  867. ds.setLoginTimeout(ConnectionTimeout);
  868. }
  869. catch (java.lang.Exception) {
  870. // WebSphere does not allows dynamicall change of login timeout
  871. // setLoginTimeout is not supported yet
  872. // in Tomcat data source.
  873. // In this case we work wthout timeout.
  874. }
  875. return ds.getConnection();
  876. }
  877. internal virtual Connection GetConnectionFromJdbcDriver()
  878. {
  879. string[] jdbcDriverStr = StringManager.GetStringArray("JDBC_DRIVER");
  880. string[] jdbcUrlStr = StringManager.GetStringArray("JDBC_URL");
  881. string jdbcDriverName = ConnectionStringHelper.FindValue(UserParameters,jdbcDriverStr);
  882. string jdbcUrl = ConnectionStringHelper.FindValue(UserParameters,jdbcUrlStr);
  883. ActivateJdbcDriver(jdbcDriverName);
  884. DriverManager.setLoginTimeout(ConnectionTimeout);
  885. java.util.Properties properties = BuildProperties();
  886. return DriverManager.getConnection(jdbcUrl,properties);
  887. }
  888. internal ArrayList GetProcedureColumns(String procedureString, AbstractDbCommand command)
  889. {
  890. ArrayList col = new ArrayList();
  891. try {
  892. ObjectNameResolver[] nameResolvers = SyntaxPatterns;
  893. ResultSet res = null;
  894. string catalog = null;
  895. string schema = null;
  896. string spname = null;
  897. DatabaseMetaData metadata = JdbcConnection.getMetaData();
  898. bool storesUpperCaseIdentifiers = false;
  899. bool storesLowerCaseIdentifiers = false;
  900. try {
  901. storesUpperCaseIdentifiers = metadata.storesUpperCaseIdentifiers();
  902. storesLowerCaseIdentifiers = metadata.storesLowerCaseIdentifiers();
  903. }
  904. catch (SQLException e) {
  905. // suppress
  906. }
  907. for(int i=0; i < nameResolvers.Length; i++) {
  908. ObjectNameResolver nameResolver = nameResolvers[i];
  909. Match match = nameResolver.Match(procedureString);
  910. if (match.Success) {
  911. spname = ObjectNameResolver.GetName(match);
  912. schema = ObjectNameResolver.GetSchema(match);
  913. catalog = ObjectNameResolver.GetCatalog(match);
  914. // make all identifiers uppercase or lowercase according to database metadata
  915. if (storesUpperCaseIdentifiers) {
  916. spname = (spname.Length > 0) ? spname.ToUpper() : null;
  917. schema = (schema.Length > 0) ? schema.ToUpper() : null;
  918. catalog = (catalog.Length > 0) ? catalog.ToUpper() : null;
  919. }
  920. else if (storesLowerCaseIdentifiers) {
  921. spname = (spname.Length > 0) ? spname.ToLower() : null;
  922. schema = (schema.Length > 0) ? schema.ToLower() : null;
  923. catalog = (catalog.Length > 0) ? catalog.ToLower() : null;
  924. }
  925. else {
  926. spname = (spname.Length > 0) ? spname : null;
  927. schema = (schema.Length > 0) ? schema : null;
  928. catalog = (catalog.Length > 0) ? catalog : null;
  929. }
  930. // catalog from db is always in correct caps
  931. if (catalog == null) {
  932. catalog = JdbcConnection.getCatalog();
  933. }
  934. try {
  935. // always get the first procedure that db returns
  936. res = metadata.getProcedures(catalog, schema, spname);
  937. if (res.next()) {
  938. catalog = res.getString(1);
  939. schema = res.getString(2);
  940. spname = res.getString(3);
  941. break;
  942. }
  943. spname = null;
  944. }
  945. catch { // suppress exception
  946. return null;
  947. }
  948. finally {
  949. if (res != null) {
  950. res.close();
  951. }
  952. }
  953. }
  954. }
  955. if (spname == null || spname.Length == 0) {
  956. return null;
  957. }
  958. try {
  959. // get procedure columns based o procedure metadata
  960. res = metadata.getProcedureColumns(catalog, schema, spname, null);
  961. while (res.next()) {
  962. // since there is still a possibility that some of the parameters to getProcedureColumn were nulls,
  963. // we need to filter the results with strict matching
  964. if ((res.getString(1) != catalog ) || (res.getString(2) != schema) || (res.getString(3) != spname)) {
  965. continue;
  966. }
  967. AbstractDbParameter parameter = (AbstractDbParameter)command.CreateParameter();
  968. parameter.SetParameterName(res);
  969. parameter.SetParameterDbType(res);
  970. parameter.SetSpecialFeatures(res);
  971. //get parameter direction
  972. short direction = res.getShort("COLUMN_TYPE");
  973. if(direction == 1) //DatabaseMetaData.procedureColumnIn
  974. parameter.Direction = ParameterDirection.Input;
  975. else if(direction == 2) //DatabaseMetaData.procedureColumnInOut
  976. parameter.Direction = ParameterDirection.InputOutput;
  977. else if(direction == 4) //DatabaseMetaData.procedureColumnOut
  978. parameter.Direction = ParameterDirection.Output;
  979. else if(direction == 5) //DatabaseMetaData.procedureColumnReturn
  980. parameter.Direction = ParameterDirection.ReturnValue;
  981. //get parameter precision and scale
  982. parameter.SetParameterPrecisionAndScale(res);
  983. parameter.SetParameterSize(res);
  984. parameter.SetParameterIsNullable(res);
  985. col.Add(parameter);
  986. }
  987. }
  988. finally {
  989. if (res != null) {
  990. res.close();
  991. }
  992. }
  993. }
  994. catch(Exception e) {
  995. //supress
  996. #if DEBUG
  997. Console.WriteLine("Exception catched at AbstractDBConnection.GetProcedureColumns() : {0}\n{1}\n{2}",e.GetType().FullName,e.Message,e.StackTrace);
  998. #endif
  999. }
  1000. return col;
  1001. }
  1002. protected static void ActivateJdbcDriver(string driver)
  1003. {
  1004. if(driver != null) {
  1005. try {
  1006. java.lang.Class.forName(driver).newInstance();
  1007. }
  1008. catch (java.lang.ClassNotFoundException e) {
  1009. throw new TypeLoadException(e.Message);
  1010. }
  1011. catch (java.lang.InstantiationException e) {
  1012. throw new MemberAccessException(e.Message);
  1013. }
  1014. catch (java.lang.IllegalAccessException e) {
  1015. throw new MissingMethodException(e.Message);
  1016. }
  1017. }
  1018. }
  1019. protected String BuildMsSqlUrl()
  1020. {
  1021. return StringManager.GetString("SQL_JDBC_URL") //"jdbc:microsoft:sqlserver://"
  1022. + ServerName + ":" + Port + ";DatabaseName=" + CatalogName;
  1023. }
  1024. #endregion // Methods
  1025. }
  1026. }