• MapInfo连接SQLServer


     1 private void ConnSqlServer()
     2        {
     3            //连接数据库
     4            MIConnection conn = new MIConnection();
     5            try
     6            {
     7                conn.Open();
     8                //XY绑定:含有x,y坐标点的图层放置在Sql Server数据库中,按xy坐标生成点图层
     9             
    10                //建立XY空间方案
    11                MapInfo.Data.SpatialSchemaXY spatialSchemaXY = new SpatialSchemaXY();
    12                MapInfo.Geometry.CoordSysFactory coordSysFactory = new CoordSysFactory();
    13                spatialSchemaXY.XColumn = "min_lvl";
    14                spatialSchemaXY.YColumn = "max_lvl";
    15                spatialSchemaXY.NullPoint = "0.0,0.0";
    16                spatialSchemaXY.StyleType = MapInfo.Data.StyleType.None;
    17                spatialSchemaXY.DefaultStyle = new MapInfo.Styles.SimpleVectorPointStyle(34, Color.Red, 15);
    18                spatialSchemaXY.CoordSys = MapInfo.Engine.Session.Current.CoordSysFactory.CreateFromPrjString("1,0");
    19                //建立TableInfo
    20               // MapInfo.Data.TableInfoServer ti = new MapInfo.Data.TableInfoServer("Customers", "Driver={SQL Server};Server=LIXIAOHUI;Database=test;Uid=sa;Pwd=sa;", "select * from Us_Cust", MapInfo.Data.ServerToolkit.Odbc);
    21                TableInfoServer tis = new TableInfoServer("TestConn");
    22                tis.ConnectString = "DRIVER={SQL SERVER};SERVER=(local);DATABASE=pubs;UID=sa;PWD=;";
    23                tis.Toolkit = ServerToolkit.Odbc;
    24                tis.Query = "select * from jobs";
    25                tis.SpatialSchema = spatialSchemaXY;
    26                tis.Temporary = true;
    27                MapInfo.Data.Table table = null;
    28                table = conn.Catalog.OpenTable(tis);
    29                if (table != null)
    30                {
    31                    FeatureLayer fl = new FeatureLayer(table);
    32                    fl.VolatilityHint = MapInfo.Mapping.LayerVolatilityHint.CacheIfPossible;
    33                    MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[0];
    34                    map.Layers.Add(fl);
    35                    MessageBox.Show("Open Server data successful!");
    36                }

    37            }

    38            catch (SqlException sqlEx)
    39            {
    40                MessageBox.Show(sqlEx.ToString());
    41            }

    42            finally
    43            {
    44                conn.Close();
    45            }

    46       }
  • 相关阅读:
    配置centOS下的Python
    linux基础命令2
    linux基础命令1
    linux常用命令(运维用到)
    Lab 10-2
    Lab 10-1
    Lab 9-3
    archlinux 装完系统连接 wifi 网络
    arch Linux(二)
    arch Linux 安装完,无法通过 SSH 远程连接 root 用户问题
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/1012701.html
Copyright © 2020-2023  润新知