Wiki source code of Configure Microsoft SQL Server

Last modified by superadmin on 2026/11/25 21:31

Show last authors
1 {{warning}}
2 Microsoft SQL Server is not one of the [[databases XWiki supports>>dev:Community.SupportStrategy.DatabaseSupportStrategy]] and gets no regular testing. If what you want is a database that is tested, the supported ones are [[MySQL>>doc:documentation.xs.admin.installation.install-relational-database.configure-mysql.WebHome]], [[MariaDB>>doc:documentation.xs.admin.installation.install-relational-database.configure-mariadb.WebHome]], [[PostgreSQL>>doc:documentation.xs.admin.installation.install-relational-database.configure-postgresql-manually.WebHome]] and [[Oracle>>doc:documentation.xs.admin.installation.install-relational-database.configure-oracle-manually.WebHome]], plus [[HSQLDB>>doc:documentation.xs.admin.installation.install-relational-database.configure-hsqldb.WebHome]], which runs embedded rather than as a server.
3 {{/warning}}
4
5 You need a [[Microsoft SQL Server>>https://www.microsoft.com/sql-server]] database server you administer.
6
7 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed.
8 1. Connect to the SQL Server instance as an administrator, with ##sqlcmd## or SQL Server Management Studio, and create the database and the login XWiki will connect with. The steps below use ##xwiki## as the password to keep them readable; pick a real one for anything but a test instance.(((
9 {{code language="sql"}}
10 CREATE DATABASE xwiki;
11 GO
12 CREATE LOGIN xwiki WITH PASSWORD = 'xwiki', DEFAULT_DATABASE = xwiki;
13 GO
14 {{/code}}
15 )))
16 1. Make that login the owner of the database, which is what lets XWiki create its tables and the schema below.(((
17 {{code language="sql"}}
18 ALTER AUTHORIZATION ON DATABASE::xwiki TO xwiki;
19 GO
20 {{/code}}
21 )))
22 1. Create a schema named after the database. XWiki qualifies the tables it maps with the name of the wiki's database, which SQL Server reads as a schema, and Hibernate creates tables but never a schema; skipping this stops the first start-up with [[an "Error executing DDL" failure>>doc:documentation.xs.admin.installation.install-relational-database.configure-mssql.error-executing-ddl.WebHome]].(((
23 {{code language="sql"}}
24 USE xwiki;
25 GO
26 CREATE SCHEMA xwiki AUTHORIZATION dbo;
27 GO
28 {{/code}}
29 )))
30 1. Download the [[Microsoft JDBC Driver for SQL Server>>https://learn.microsoft.com/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server]], either from Microsoft or from the [[Maven Central repository>>https://central.sonatype.com/artifact/com.microsoft.sqlserver/mssql-jdbc]], and copy the jar built for the Java version your servlet container runs into the ##WEB-INF/lib## directory of the expanded XWiki WAR. XWiki ships no SQL Server driver.(((
31 {{code language="none"}}
32 $ cp mssql-jdbc-*.jre11.jar /path/to/webapps/xwiki/WEB-INF/lib/
33 {{/code}}
34 )))
35 1. Edit the ##WEB-INF/hibernate.cfg.xml## file of the expanded XWiki WAR, comment out the database block that is currently active, and add the block below inside ##<session-factory>##. SQL Server, like DB2, has no commented-out block of its own in that file, so you write it rather than uncomment it. Replace ##localhost## with the host running SQL Server if it is not the XWiki machine. The connection pool, the connection provider and ##hibernate.jdbc.use_scrollable_resultset## are already set in the generic section at the top of the same file, the last one for SQL Server in particular, so the block does not repeat them.(((
36 {{code language="xml"}}
37 <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=xwiki;encrypt=true;trustServerCertificate=true</property>
38 <property name="hibernate.connection.username">xwiki</property>
39 <property name="hibernate.connection.password">xwiki</property>
40 <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
41
42 <property name="hibernate.connection.charSet">UTF-8</property>
43 <property name="hibernate.connection.useUnicode">true</property>
44 <property name="hibernate.connection.characterEncoding">utf8</property>
45
46 <mapping resource="xwiki.mssql.hbm.xml"/>
47 <mapping resource="feeds.hbm.xml"/>
48 <mapping resource="instance.hbm.xml"/>
49 <mapping resource="notification-filter-preferences.hbm.xml"/>
50 <mapping resource="mailsender.hbm.xml"/>
51 {{/code}}
52 )))
53 1. Leave ##hibernate.dialect## out: Hibernate reads the SQL Server version from the connection and picks the matching dialect by itself. Naming one by hand, as older instructions did, pins a dialect older than the server and is what makes [[a wiki search case-sensitive>>doc:documentation.xs.admin.installation.install-relational-database.configure-mssql.case-sensitive-search.WebHome]] on instances set up that way.
54 1. Decide how the connection is encrypted. The driver has encrypted connections on by default since version 10.2, so a server presenting a self-signed certificate is refused unless you either install a certificate the JVM trusts and drop ##trustServerCertificate## from the URL, or keep ##trustServerCertificate=true## and accept that the certificate is not checked.
55 1. Start or restart the application server. XWiki creates its tables on the first run.
56 1. Verify that the tables are there, by listing the ones created in the ##xwiki## database.(((
57 {{code language="none"}}
58 $ sqlcmd -S localhost -U xwiki -P xwiki -d xwiki -Q "SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME"
59
60 TABLE_SCHEMA TABLE_NAME
61 -------------- --------------------
62 xwiki xwikiattachment
63 xwiki xwikidoc
64 xwiki xwikiobjects
65 xwiki xwikispace
66 {{/code}}
67 )))

Get Connected