sqlserver.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .. _data_sqlserver:
  2. Microsoft SQL Server and SQL Azure
  3. ==================================
  4. .. note:: GeoServer does not come built-in with support for SQL Server; it must be installed through an extension. Proceed to :ref:`sqlserver_install` for installation details.
  5. Microsoft's `SQL Server <http://www.microsoft.com/sqlserver>`_ is a relational database with spatial functionality. SQL Azure is the database option provided in the Azure cloud solution which is in many respects similar to SQL Server.
  6. Supported versions
  7. ------------------
  8. The extension supports SQL Server 2008 - 2019 and SQL Azure.
  9. .. _sqlserver_install:
  10. Installing the SQL Server extension
  11. -----------------------------------
  12. GeoServer files
  13. ```````````````
  14. #. Visit the :website:`website download <download>` page, locate your release, and download: :download_extension:`sqlserver`
  15. .. warning:: Ensure to match plugin (example |release| above) version to the version of the GeoServer instance.
  16. #. Extract the contents of the archive into the :file:`WEB-INF/lib` directory of the GeoServer installation.
  17. #. Restart the GeoServer to load the extension.
  18. Adding a SQL Server database
  19. ----------------------------
  20. Once the extension is properly installed ``SQL Server`` will show up as an option when creating a new data store.
  21. .. figure:: images/sqlservercreate.png
  22. :align: center
  23. *SQL Server in the list of vector data sources*
  24. Configuring a SQL Server data store
  25. -----------------------------------
  26. .. figure:: images/sqlserverconfigure.png
  27. :align: center
  28. *Configuring a SQL Server data store*
  29. .. list-table::
  30. :widths: 20 80
  31. * - ``host``
  32. - The sql server instance host name or ip address, only. Note that ``server\instance`` notation is not accepted - specify the port below, instead, if you have a non-default instance.
  33. * - ``port``
  34. - The port on which the SQL server instance is accepting connections. See the :ref:`note <port_notes>` below.
  35. * - ``database``
  36. - The name of the database to connect to. Might be left blank if the user connecting to SQL Server has a "default database" set in the user configuration
  37. * - ``schema``
  38. - The database schema to access tables from (optional).
  39. * - ``user``
  40. - The name of the user to connect to the database as.
  41. * - ``password``
  42. - The password to use when connecting to the database. Leave blank for no password.
  43. * - ``max connections`` ``min connections``
  44. - Connection pool configuration parameters. See the :ref:`connection_pooling` section for details. If you are connecting to SQL Azure make sure to set the ``validate connections`` flag as SQL Azure closes inactive connections after a very short delay.
  45. .. _port_notes:
  46. Determining the port used by the SQL Server instance
  47. ````````````````````````````````````````````````````
  48. You can determine the port in use by connecting to your SQL server instance using some other software, and then using :command:`netstat` to display details on network connections. In the following example on a Windows PC, the port is 2646 :
  49. .. code-block:: batch
  50. C:\>netstat -a | find "sql1"
  51. ::
  52. TCP DPI908194:1918 maittestsql1.dpi.nsw.gov.au:2646 ESTABLISHED
  53. Using the geometry metadata table
  54. `````````````````````````````````
  55. The SQL server data store can determine the geometry type and native SRID of a particular column only by data inspection,
  56. by looking at the first row in the table. Of course this is error prone, and works only if there is data in the table.
  57. The administrator can address the above issue by manually creating a geometry metadata table describing each geometry column.
  58. Its presence is indicated via the SQL Server datastore connection parameter named *Geometry metadata table*
  59. (which may be a simple table name or a schema-qualified one).
  60. The table has the following structure (the table name is flexible, just specify the one chosen in the data store connection parameter):
  61. .. code-block:: sql
  62. CREATE TABLE GEOMETRY_COLUMNS(
  63. F_TABLE_SCHEMA VARCHAR(30) NOT NULL,
  64. F_TABLE_NAME VARCHAR(30) NOT NULL,
  65. F_GEOMETRY_COLUMN VARCHAR(30) NOT NULL,
  66. COORD_DIMENSION INTEGER,
  67. SRID INTEGER NOT NULL,
  68. TYPE VARCHAR(30) NOT NULL,
  69. UNIQUE(F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN),
  70. CHECK(TYPE IN ('POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') ));
  71. When the table is present the store first searches it for information about each geometry column
  72. to be classified, and falls back on data inspection only if the table does not contain any information.