@@ -97,46 +97,54 @@ public SqliteConnectionInternal(SqliteConnectionStringBuilder connectionOptions,
97
97
? connectionOptions . Vfs
98
98
: null ;
99
99
var rc = sqlite3_open_v2 ( filename , out _db , flags , vfs : vfs ) ;
100
- SqliteException . ThrowExceptionForRC ( rc , _db ) ;
101
-
102
- if ( connectionOptions . Password . Length != 0 )
100
+ try
103
101
{
104
- if ( SQLitePCLExtensions . EncryptionSupported ( out var libraryName ) == false )
102
+ SqliteException . ThrowExceptionForRC ( rc , _db ) ;
103
+
104
+ if ( connectionOptions . Password . Length != 0 )
105
105
{
106
- throw new InvalidOperationException ( Resources . EncryptionNotSupported ( libraryName ) ) ;
106
+ if ( SQLitePCLExtensions . EncryptionSupported ( out var libraryName ) == false )
107
+ {
108
+ throw new InvalidOperationException ( Resources . EncryptionNotSupported ( libraryName ) ) ;
109
+ }
110
+
111
+ // NB: SQLite doesn't support parameters in PRAGMA statements, so we escape the value using the
112
+ // quote function before concatenating.
113
+ var quotedPassword = ExecuteScalar (
114
+ "SELECT quote($password);" ,
115
+ connectionOptions . Password ,
116
+ connectionOptions . DefaultTimeout ) ;
117
+ ExecuteNonQuery (
118
+ "PRAGMA key = " + quotedPassword + ";" ,
119
+ connectionOptions . DefaultTimeout ) ;
120
+
121
+ if ( SQLitePCLExtensions . EncryptionSupported ( ) != false )
122
+ {
123
+ // NB: Forces decryption. Throws when the key is incorrect.
124
+ ExecuteNonQuery (
125
+ "SELECT COUNT(*) FROM sqlite_master;" ,
126
+ connectionOptions . DefaultTimeout ) ;
127
+ }
107
128
}
108
129
109
- // NB: SQLite doesn't support parameters in PRAGMA statements, so we escape the value using the
110
- // quote function before concatenating.
111
- var quotedPassword = ExecuteScalar (
112
- "SELECT quote($password);" ,
113
- connectionOptions . Password ,
114
- connectionOptions . DefaultTimeout ) ;
115
- ExecuteNonQuery (
116
- "PRAGMA key = " + quotedPassword + ";" ,
117
- connectionOptions . DefaultTimeout ) ;
118
-
119
- if ( SQLitePCLExtensions . EncryptionSupported ( ) != false )
130
+ if ( connectionOptions . ForeignKeys . HasValue )
120
131
{
121
- // NB: Forces decryption. Throws when the key is incorrect.
122
132
ExecuteNonQuery (
123
- "SELECT COUNT(*) FROM sqlite_master ;" ,
133
+ "PRAGMA foreign_keys = " + ( connectionOptions . ForeignKeys . Value ? "1" : "0" ) + " ;",
124
134
connectionOptions . DefaultTimeout ) ;
125
135
}
126
- }
127
136
128
- if ( connectionOptions . ForeignKeys . HasValue )
129
- {
130
- ExecuteNonQuery (
131
- "PRAGMA foreign_keys = " + ( connectionOptions . ForeignKeys . Value ? "1" : "0" ) + ";" ,
132
- connectionOptions . DefaultTimeout ) ;
137
+ if ( connectionOptions . RecursiveTriggers )
138
+ {
139
+ ExecuteNonQuery (
140
+ "PRAGMA recursive_triggers = 1;" ,
141
+ connectionOptions . DefaultTimeout ) ;
142
+ }
133
143
}
134
-
135
- if ( connectionOptions . RecursiveTriggers )
144
+ catch
136
145
{
137
- ExecuteNonQuery (
138
- "PRAGMA recursive_triggers = 1;" ,
139
- connectionOptions . DefaultTimeout ) ;
146
+ _db . Dispose ( ) ;
147
+ throw ;
140
148
}
141
149
142
150
_pool = pool ;
0 commit comments