wyq 3 månader sedan
förälder
incheckning
a80b15e25d
2 ändrade filer med 33 tillägg och 17 borttagningar
  1. 2 2
      DW5S.App/App.config
  2. 31 15
      DW5S.App/ExtensionsDev/MapControlEx.cs

+ 2 - 2
DW5S.App/App.config

@@ -17,8 +17,8 @@
 	</applicationSettings>
 	<connectionStrings>
 		<add name="OracleCon" connectionString="Data Source=192.168.1.111:1521/ORCL;User ID=DW5S;Password=123456"/>
-
-		<add name="SqliteCon" connectionString="Data Source=D:/work/DW5S/DW5S.App/dw5s.db"/>
+		<add name="SqliteCon" connectionString="Data Source=dw5s.db"/>
+		<!--<add name="SqliteCon" connectionString="Data Source=D:/work/DW5S/DW5S.App/dw5s.db"/>-->
 	</connectionStrings>
 	<appSettings>
 		<!--程序标题-->

+ 31 - 15
DW5S.App/ExtensionsDev/MapControlEx.cs

@@ -944,9 +944,12 @@ public static class MapControlEx
             try
             {
                 string conStr = string.Format("Data Source=\"{0}\"", files[0]);
-               // string conStr = string.Format("Data Source=\"{0}\";Page Size=32768", files[0]);
+                //string conStr = string.Format("Data Source=\"{0}\";Page Size=32768", files[0]);
                 var con = new Microsoft.Data.Sqlite.SqliteConnection(conStr);
                 con.Open();
+                using var cmd = con.CreateCommand();
+                cmd.CommandText = "PRAGMA mode=ReadOnly;";
+                cmd.ExecuteNonQuery();
                 con.Close();
                 localGmdbDataEnable = true;
             }
@@ -2947,7 +2950,6 @@ public static class MapControlEx
     #region ImageLayer数据源接口实现(本地和Http接口)
     class ImageTileSource : IImageTileSource
     {
-        Microsoft.Data.Sqlite.SqliteConnection con;
         public ImageTileSource()
         {
             var files = Directory.GetFiles(Application.StartupPath, "Data.gmdb", SearchOption.AllDirectories);
@@ -2956,8 +2958,11 @@ public static class MapControlEx
                 try
                 {
                     conStr = string.Format(conStr, files[0]);
-                    con = new Microsoft.Data.Sqlite.SqliteConnection(conStr);
-                    con.Open();
+                    using (var con = new Microsoft.Data.Sqlite.SqliteConnection(conStr))
+                    {
+                        con.Open();
+                    }
+
                 }
                 catch
                 {
@@ -2981,26 +2986,37 @@ public static class MapControlEx
             return Image.FromStream(new MemoryStream(data));
         }
         string QuerySql = "SELECT Tile FROM main.TilesData WHERE id = (SELECT id FROM main.Tiles WHERE X={0} AND Y={1} AND Zoom={2} AND Type={3})";
-        string conStr = "Data Source=\"{0}\";Page Size=32768";
+        string conStr = "Data Source=\"{0}\"";
         byte[] QueryTile(int x, int y, int zoom, int type)
         {
             if (conStr == null) return null;
-            type = (int)mMapType;
-            if (type == 0) type = 1818940751;
-            using (DbCommand com = con.CreateCommand())
+            try
             {
-                com.CommandText = string.Format(QuerySql, x, y, zoom, type);
-                using (DbDataReader rd = com.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
+                using (var con = new Microsoft.Data.Sqlite.SqliteConnection(conStr))
                 {
-                    if (rd.Read())
+                    con.Open();
+                    type = (int)mMapType;
+                    if (type == 0) type = 1818940751;
+                    using (DbCommand com = con.CreateCommand())
                     {
-                        long length = rd.GetBytes(0, 0, null, 0, 0);
-                        byte[] tile = new byte[length];
-                        rd.GetBytes(0, 0, tile, 0, tile.Length);
-                        return tile;
+                        com.CommandText = string.Format(QuerySql, x, y, zoom, type);
+                        using (DbDataReader rd = com.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
+                        {
+                            if (rd.Read())
+                            {
+                                long length = rd.GetBytes(0, 0, null, 0, 0);
+                                byte[] tile = new byte[length];
+                                rd.GetBytes(0, 0, tile, 0, tile.Length);
+                                return tile;
+                            }
+                        }
+
                     }
                 }
             }
+            catch (Exception ex)
+            {
+            }
             return null;
         }
     }