Microsoft SQL Server Installation
Create the xwiki user and database
- Use the multi-wiki feature to create a database named "XWiki" and a user named "xwiki"
- Set xwiki's password to xwiki
- Give database ownership of the XWiki database to the "xwiki" user
Install the JDBC driver
- Download the jtds jdbc driver and install the jar file into your server's lib directory (for JBoss this could be server\default\lib\, for Tomcat this might be common\lib\)
- Alternatively, you can use the JDBC driver provided by Microsoft, however this has not been thoroughly tested
XWiki configuration
- Configure XWiki to use MSSQL. To do this, edit the WEB-INF/hibernate.cfg.xml file. Replace the matching properties with the following ones (or uncomment them if they are present):
JTDS
<property name="connection.username">xwiki</property>
<property name="connection.password">xwiki</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.pool_size">2</property>
<property name="statement_cache.size">2</property>
<mapping resource="xwiki.mssql.hbm.xml"></mapping>
<mapping resource="feeds.hbm.xml"></mapping>
<mapping resource="activitystream.hbm.xml"></mapping>
MS JDBC driver
<property name="connection.username">xwiki</property>
<property name="connection.password">xwiki</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.pool_size">2</property>
<property name="statement_cache.size">2</property>
<mapping resource="xwiki.mssql.hbm.xml"></mapping>
<mapping resource="feeds.hbm.xml"></mapping>
<mapping resource="activitystream.hbm.xml"></mapping>
Troubleshooting
Fix search function
If you try to do a search, via WebSearch, you will get an error. This is because the UPPER() function doesn't work on TEXT or NTEXT as used by MSSQL 2000 for blobs. The only solution I have found is to remove all the calls to UPPER() in WebSearch. This is however not very practical, because it makes search case-sensitive.
Alternatively, you may want to use the Lucene search application instead of the default search.
Fix filter in Livetable Macro
The filter function in the Livetable Macro is not working on MSSQL. The macro function livetable_addColumnToQuery (defined in XWiki.LiveTableResultsMacros) uses in an HQL Statement the function str (Line 576) with an string parameter. This function call is not correctly mapped to the SQL statement.
A solution to fix the problem is to implement an extension of the SQLServerDialect class to be able to overwrite the registration of the STR function through the following one:
{
/**
* constructor
*/
public WikiSQLServerDialect()
{
super();
registerFunction("str", new SQLFunctionTemplate(StandardBasicTypes.STRING, "cast(?1 as varchar)"));
}
}
An XWiki extension is available for XWiki 6.2.2 (and later): SQL Server Hibernate Dialect for XWiki
For details see also Issue XWIKI-10606 on Jira.
Fix Error Executing DDL with MSSQL Server 2019
If you see the following error message when deploying XWiki with MSSQL Server 2019 and Tomcat9: -
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table xwiki.activitystream_events (ase_eventid varchar(48) not null, ase_requestid varchar(48), ase_stream varchar(255), ase_date datetime, ase_priority int, ase_type varchar(255), ase_application varchar(255), ase_user varchar(255), ase_wiki varchar(255), ase_space varchar(255), ase_page varchar(255), ase_hidden bit, ase_url text, ase_title text, ase_body text, ase_version varchar(30), ase_param1 text, ase_param2 text, ase_param3 text, ase_param4 text, ase_param5 text, primary key (ase_eventid))" via JDBC Statement
This can be fixed by creating the Schema manually in your MSSQL database. Queries generated by Hibernate only create the tables, not Schema, so if you create a Schema manually and assign it to a relevant owner then it will fix the error mentioned above.
For details, please visit Issue XWiki-18318.
Hints for upgrading to MS SQL 2005
In MS SQL 2005 the standard schema in all databases is dbo by default. However, if you upgrade your server with the standard Microsoft software, all tables in your xwiki database will be configured to use a schema whichs name is equivalent to the database name. (If your database name is "xwiki", the schema name will also be "xwiki" and the full qualified tablenames will be "xwiki.xwikidoc", and so on).
Since the standard schema is configured to be "dbo", xwiki will not find any tables (since it searches for "dbo.xwikidoc", ...). This will result in an exception when calling the xwiki webapp (in the logfiles you will see an "object not found" - exception for xwikidoc, because xwikidoc is the first table to be mapped via hibernate).
There are 2 possible solutions to this problem:
- Reconfigure your server to use "xwiki" as the standard scheme inside the xwiki-database
- Adopt the hibernate file (xwiki.mssql.hbm.xml). Look for the table definitions, eg. table="xwikidoc" and set it to table="xwiki.xwikidoc" or to whatever your schema/database is called. Do this for all the tables you can find in the file.