public void Open() { if (State != ConnectionState.Closed) { throw new SqliteException("There is already an open connection"); } var connectionData = ParseConnectionString(ConnectionString); var openParam = string.Empty; if (connectionData.ContainsKey("uri")) { openParam = connectionData["uri"]; if (openParam.StartsWith("file:")) { openParam = openParam.Substring(5); } } IntPtr conn; var retVal = UnsafeNativeMethods.Open(openParam, out conn, UnsafeNativeMethods.OpenFlags.ReadWrite | UnsafeNativeMethods.OpenFlags.URI, null); if (retVal != UnsafeNativeMethods.ResultCode.OK) { throw new SqliteException(GetError(conn) + " - " + retVal + " ConnectionString: " + ConnectionString); } NativeConnection = conn; State = ConnectionState.Open; }
public static void CreateFile(string databaseFileName) { var dirName = Path.GetDirectoryName(databaseFileName); if (string.IsNullOrEmpty(dirName) == false && Directory.Exists(dirName) == false) { Directory.CreateDirectory(dirName); } IntPtr conn; var retVal = UnsafeNativeMethods.Open(databaseFileName, out conn, UnsafeNativeMethods.OpenFlags.ReadWrite | UnsafeNativeMethods.OpenFlags.Create, null); if (retVal != UnsafeNativeMethods.ResultCode.OK) { throw new SqliteException(GetError(conn) + " - " + retVal); } UnsafeNativeMethods.Close(conn); }