Version 20.4 by Vincent Massol on 2017/09/06

Show last authors
1 {{info}}
2 This has been tested on MSSQL 2000 and MSSQL 2005 (text types are only deprecated in MSSQL 2005; this tutorial won't work when they'll be dropped).
3 {{/info}}
4
5 {{warning}}
6 Case-insensitive search does not work with this database; see below for more info. You may want to use the the [[Lucene search application>>extensions:Extension.Search Application]].
7 {{/warning}}
8
9 = Create the xwiki user and database =
10
11 * Use the [[multi-wiki feature>>extensions:Extension.Wiki Application]] to create a database named "XWiki" and a user named "xwiki"
12 * Set xwiki's password to //xwiki//
13 * Give database ownership of the XWiki database to the "xwiki" user
14
15 = Install the JDBC driver =
16
17 * Download the [[jtds jdbc driver>>http://sourceforge.net/projects/jtds/]] 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\##)(((
18 {{info}}
19 The connection was successfully tested with version 1.2.1 of the driver and version 1.5 of XWiki. Some problems occurred when using drivers > 1.2.1 so it might be better to use the old one.
20 {{/info}}
21 )))
22 * Alternatively, you can use the [[JDBC driver provided by Microsoft>>http://www.microsoft.com/en-us/download/details.aspx?id=21599]], however this has not been thoroughly tested
23
24 = XWiki configuration =
25
26 * 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):
27
28 == JTDS ==
29
30 {{code language="xml"}}
31 <property name="connection.url">jdbc:jtds:sqlserver://<server-url>:1433/XWiki;tds=8.0;lastupdatecount=true</property>
32 <property name="connection.username">xwiki</property>
33 <property name="connection.password">xwiki</property>
34 <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
35 <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
36 <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
37 <property name="connection.pool_size">2</property>
38 <property name="statement_cache.size">2</property>
39 <mapping resource="xwiki.mssql.hbm.xml"/>
40 <mapping resource="feeds.hbm.xml"/>
41 <mapping resource="activitystream.hbm.xml"/>
42 {{/code}}
43
44 == MS JDBC driver ==
45
46 {{info}}
47 Copy //sqljdbc.jar// from the downloaded package into ##\webapps\xwiki\WEB-INF\lib\##. If you have installed Sun JRE 1.6 (or above) you need to copy //**sqljdbc4.jar**// instead!
48 {{/info}}
49
50 {{code language="xml"}}
51 <property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=XWiki</property>
52 <property name="connection.username">xwiki</property>
53 <property name="connection.password">xwiki</property>
54 <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
55 <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
56 <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
57 <property name="connection.pool_size">2</property>
58 <property name="statement_cache.size">2</property>
59 <mapping resource="xwiki.mssql.hbm.xml"/>
60 <mapping resource="feeds.hbm.xml"/>
61 <mapping resource="activitystream.hbm.xml"/>
62 {{/code}}
63
64 = Troubleshooting =
65
66 == Fix search function ==
67
68 If you try to do a search, via [[platform:Main.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 [[platform:Main.WebSearch]]. This is however not very practical, because it makes search case-sensitive.
69
70 Alternatively, you may want to use the [[Lucene search application>>extensions:Extension.Search Application]] instead of the default search.
71
72
73 == Fix filter in Livetable Macro ==
74
75 The filter function in the [[Livetable Macro>>doc:extensions:Extension.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.
76 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:
77
78 {{code language="java"}}
79 public class IWikiSQLServerDialect extends SQLServerDialect
80 {
81 /**
82 * constructor
83 */
84 public WikiSQLServerDialect()
85 {
86 super();
87 registerFunction("str", new SQLFunctionTemplate(StandardBasicTypes.STRING, "cast(?1 as varchar)"));
88 }
89 }
90 {{/code}}
91
92 An XWiki extension is available for XWiki 6.2.2 (and later): [[SQL Server Hibernate Dialect for XWiki>>extensions:Extension.SQL Server Hibernate Dialect for XWiki]]
93
94 For details see also [[Issue XWIKI-10606>>https://jira.xwiki.org/browse/XWIKI-10606]] on Jira.
95
96 == Hints for upgrading to MS SQL 2005 ==
97
98 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).
99
100 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).
101
102 There are 2 possible solutions to this problem:
103
104 * Reconfigure your server to use "xwiki" as the standard scheme inside the xwiki-database
105 * 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.

Get Connected