You are on page 1of 27

TAFJ-M S S QL I n s t all

R18
TAFJ-M S S QL I n s t all

Amendment History:

Revisio
Date Amended Name Description
n
11 1st April 2011 TAFJ team Initial version
7st February
12 H. Aubert R12GA review
2012
16th January
13 R. Vincent R13GA review
2013
14 29th April 2013 R. Vincent R13GA review update

15 2nd Feb. 2014 R. Vincent R14GA review

16 4th Feb 2015 G.Gowrimani Altered the Collation

17 11th May 2015 G.Gowrimani Altered the Trustworthy

18 7th Jan 2016 Manojkumar. A Correction of collation

19 15th March 2016 R. Vincent R16 AMR review

20th September
20 JN. Charpin Instructions to setup XA
2017

Page 2
TAFJ-M S S QL I n s t all

Table of Contents
Instructions for SQL Server 2012 Express Edition..................................................................................4
Ensure SQL Server is started................................................................................................ 4
Create Database in Microsoft SQL Server Management...................................................... 4
Connect to Database with Visual Studio 2010...................................................................... 7
Starting from scratch with a New Visual Studio project—Connect to Database with Visual
Studio 2010......................................................................................................................... 10
Create a Database on the command line............................................................................ 14
Enable TCP/IP for jdbc data connections............................................................................................. 14
Which port am I running on?............................................................................................ 14
Loading C# Stored Functions............................................................................................................... 15
Step1................................................................................................................................... 15
Step 2.................................................................................................................................. 15
Step 3.................................................................................................................................. 17
Step 4.................................................................................................................................. 17
Step 5.................................................................................................................................. 18
Set Authentication DLL......................................................................................................................... 18
Run a DBImport.................................................................................................................................... 19
Backup and Restore the Database....................................................................................................... 19
Appendix.............................................................................................................................................. 20
Can’t create your database in SQL Server Management................................................ 20
TAFJ fails with c# stored procedures with HostProtectionException............................... 22
JDBC Driver Fails With: Failed to load the sqljdbc_auth.dll or “This driver is not
configured for integrated authentication”......................................................................... 23
SQLCMD Errors: Fails to Start....................................................................................... 23

Page 3
TAFJ-M S S QL I n s t all

Instr u c t i o n s for SQL Serv e r 20 1 2 Expr e s s Editi o n

The below instructions describe how to get a SQL Server 2012 Express Edition in a state
where the user can do a DBImport. This assumes that SQL Server 2012 Express Edition
and TAFJ have already been installed and that the install directory of TAFJ is %TAFJ_HOME
%. When downloading SQLServer 2012 Express Edition also download and install SQL
Server Management Studio Express (Tools only) and LocalDB.

Ens u r e SQL Serv e r is start e d .

Crea t e Dat a b a s e in Micr o s o f t SQL Serv e r Man a g e m e n t

After starting Microsoft SQL Server Management, in the upper left hand corner click
“Connect”. A pop up should appear as below with the <Name of your PC>\SQLEXPRESS.
Click “Connect”.

Page 4
TAFJ-M S S QL I n s t all

Once connected, you should see something similar to the below.

Right-click on “Database”, then “New Database” and you should have the following.

Page 5
TAFJ-M S S QL I n s t all

Name your database in “Database name”. Make sure collation is set to


Latin1_General_BIN2 on the “Options” tab as shown below.

NOTE: The client can choose any collation, but care should be taken to make sure the
collation accommodates ‘CASE-SENSITIVE’ as this is a requirement for TAFJ.

Page 6
TAFJ-M S S QL I n s t all

Con n e c t to Data b a s e with Visu a l Stu d i o 20 1 0 .

Now connect to your database in Visual Studio by ToolsConnect to Database, you will then
see the following:

Page 7
TAFJ-M S S QL I n s t all

Click “Continue”

Page 8
TAFJ-M S S QL I n s t all

Test the connection and then hit “OK”

Page 9
TAFJ-M S S QL I n s t all

Star ti n g fro m scr at c h with a N e w Visu a l Stu d i o proje c t—


Con n e c t to Data b a s e with Visu a l Stu d i o 20 1 0 .

Start Visual Studio 2010, click on FileNew Project. Select the database tab, then
SQL Server, then “Visual C# SQL CLR Database Project”.

Page 10
TAFJ-M S S QL I n s t all

You then should see a pop-up with your database that you just created. Select it and then hit
“OK”.

Page 11
TAFJ-M S S QL I n s t all

If you don’t see it, hit “Add New Reference” and you will be redirected to the following screen
in which case you put your computer name in “Server Name”, hit refresh, then select your
database.

Page 12
TAFJ-M S S QL I n s t all

Select “Yes” on this screen.

Page 13
TAFJ-M S S QL I n s t all

Crea t e a Data b a s e on the co m m a n d lin e .

Using SQLCMD, create a database as below.


C:\ >sqlcmd –S<Computer Name>\SQLEXPRESS -E -h-1 -y 0
1> CREATE DATABASE TESTDB COLLATE Latin1_General_BIN2
2> GO
1> Use TESTDB
2> go
Changed database context to ' TESTDB'.

Enabl e TCP/IP for jdbc data co n n e c t i o n s

Open SQL Server Configuration Manager, click on « SQL Server Network


Configuration »Protocols for SQLExpress, then in right pane right click on TCP/IP and
enable it.

Whi c h port am I run n i n g on?


By default, sqlserver should start on port 1433, but it is not always the case (for whatever
reason). You can force it by clicking on the properties of TCP/IP, clicking on the IP
Addresses tab, and doing as show below for the IPALL section where the TCP Dynamic
Ports has been erased and forced in TCP Port 1433.

Page 14
TAFJ-M S S QL I n s t all

Loadi n g C # Stor e d Fun c t i o n s

Go to %TAFJ_HOME%\dbscripts\ms-sql.

St e p 1
Alter the script csharpload.sql to your target database, default is master, (Temenos
recommends something other than this), and the full path to TAFJSQLServer.dll

St e p 2
Startup sqlcmd with: sqlcmd –S<Computer Name>\SQLEXPRESS -E -h-1 -y 0

As master db, give the following permission to your target DB

Enable clr code within your database.

Page 15
TAFJ-M S S QL I n s t all

1> use TESTDB


2> go
Changed database context to 'TESTDB'.
1> sp_configure 'clr enable', 1
2> go
1> RECONFIGURE WITH OVERRIDE
2> go
Restart the SQLServer Express addition service

Page 16
TAFJ-M S S QL I n s t all

St e p 3

Now load the c# stored functions (the output of this will go to output.txt in this example):

Launch: sqlcmd –S<Computer Name>\SQLEXPRESS -i %TAFJ_HOME%\dbscripts\ms-


sql\csharpload.sql -o output.txt

(Note that output.txt will only contain "Changed database context to TESTDB if objects
already created)

St e p 4
Now verify that functions are loaded as below on the sqlcmd prompt:
1> SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE =
'FUNCTION' ORDER BY ROUTINE_NAME
2> GO
ROUTINE_NAME
------------------------------------------------------------------------
extractValueJS
FM
SM
tafjcat
tafjcats
tafjchar
tafjconvert
tafjcount
tafjdate
tafjdcount
tafjequal
tafjfget
tafjfield
tafjfields
tafjfmt
tafjget
tafjiconv
tafjlen
tafjlower
tafjmatches
tafjmatchfield
tafjoconv
tafjraise
tafjsub
tafjsubstrings
tafjsum
VM

Page 17
TAFJ-M S S QL I n s t all

St e p 5

If something went wrong in steps 1 and 2) (unloading c# stored functions) :

- Alter the script csharpunload.sql to the database you want (default is master)

- Launch: sqlcmd -i %TAFJ_HOME%\dbscripts\ms-sql \csharpunload.sql -o output.txt

Page 18
TAFJ-M S S QL I n s t all

XA sup p o r t

A specific DLL has to be deployed to be able to perform XA transactions when a data source
is configured to use XA.

Otherwise errors mentioning missing procedures will be raised.

javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could


not find stored procedure 'master..xp_sqljdbc_xa_start'.

To enable XA please follow the following steps as instructed in the MS-SQL driver under, i.e.
sqljdbc_6.0\enu\xa\ xa_install.sql :

1- Copy the DLL from the MS-SQL driver, i.e.:

sqljdbc_6.0\enu\xa\x64\sqljdbc_xa.dll

and paste into <SQL_SERVER_HOME>\Binn

2- Execute the SQL script from the MS-SQL driver, i.e.:

sqljdbc_6.0\enu\xa\ xa_install.sql

3- Add your DB user to the role SqlJDBCXAUser, i.e.


USE master
GO
EXEC sp_grantdbaccess 'tafjuser', 'tafjuser'
GO
EXEC sp_addrolemember [SqlJDBCXAUser], 'tafjuser'

4- In case of SQLJDBC_XA DTC_ERROR, make sure that the DTC service is correctly
configured and running:

Page 19
TAFJ-M S S QL I n s t all

Running the MS DTC Service

The MS DTC service should be marked Automatic in Service Manager to make sure that it is running
when the SQL Server service is started. To enable MS DTC for XA transactions, you must follow these
steps:

On Windows Vista and later:

1. Click the Start button, type dcomcnfg in the Start Search box, and then press ENTER to
open Component Services. You can also type %windir%\system32\comexp.msc in
the StartSearch box to open Component Services.
2. Expand Component Services, Computers, My Computer, and then Distributed Transaction
Coordinator.
3. Right-click Local DTC and then select Properties.
4. Click the Security tab on the Local DTC Properties dialog box.
5. Select the Enable XA Transactions check box, and then click OK. This will cause a MS DTC
service restart.
6. Click OK again to close the Properties dialog box, and then close Component Services.
7. Stop and then restart SQL Server to make sure that it syncs up with the MS DTC changes.

To get detailed information regarding XA support you could refer to the following MS-SQL
documentation.

https://docs.microsoft.com/en-us/sql/connect/jdbc/understanding-xa-transactions

Se t Auth e n t i c a t i o n DLL

Set TCP/IP enabled using SQL Server Configuration manager and then restart the SQL
Server service.

Generally, the SQLServer default port is 4333, but could be another one (such as 53963).
Use a tool such as tcpview if you are having issues discovering it and can’t find it in SQL
Server Configuration manager or refer back to section “Which port am I running on?” You
will need the port for the JDBC url which is shown below in “Run a DBImport”

set PATH=%PATH%;%TAFJ_HOME%\ext\sqljdbc_1.2\enu\auth\x64
or
set PATH=%PATH%;%TAFJ_HOME%\ext\sqljdbc_1.2\enu\auth\x86
Make sure you are using the 32 bit one if your JVM is 32 bit, or 64 bit with a 64 bit JVM,
otherwise you get an error such as the following:

Jan 17, 2013 4:17:35 PM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>


WARNING: Failed to load the sqljdbc_auth.dll
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for
integrated authentication.

Page 20
TAFJ-M S S QL I n s t all

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown
Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(Unknown Source)
at
com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(Unknown
Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown
Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown
Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown
Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)

Run a DBI m p o r t

Please refer to TAFJ-DBSetup documentation. Typical TAFJ properties for SQL Server
(using integrated security) are shown below.
temn.tafj.jdbc.url =
jdbc:sqlserver://localhost:1433;databaseName=TESTDB;integratedSecurity=true;

temn.tafj.jdbc.driver =
com.microsoft.sqlserver.jdbc.SQLServerDriver

temn.tafj.jdbc.username =
temn.tafj.jdbc.password =

To connect to a remote Database or from a client on different windows domain or on non-


windows domain you will have to use SQL Server authentication, thus the database should
be defined with a mixed authentication mode.

You should also create a MSSQL user and grant him with DBO privilege.

temn.tafj.jdbc.url =
jdbc:sqlserver://localhost:1433;databaseName=TESTDB;

temn.tafj.jdbc.driver =
com.microsoft.sqlserver.jdbc.SQLServerDriver

temn.tafj.jdbc.username = sqlserveruser
temn.tafj.jdbc.password = sqlserveruserpwd

Page 21
TAFJ-M S S QL I n s t all

Ba c k u p and Res t o r e the Data b a s e

Here is a backup example for machine L40RB1P1:

sqlcmd –S<Computer Name>\SQLEXPRESS -E -h-1 -y 0

1> BACKUP DATABASE R12GAMBSS TO DISK =


'C:\SQLServerBackups\R12GAMBSS.bak' WITH FORMAT;
1>GO

A restore example:

1>RESTORE DATABASE R12GAMBSS FROM DISK =


'C:\SQLServerBackups\R12GAMBSS.bak';
1>GO

App e n d i x

Can’t cre a t e your data b a s e in SQL Serv e r Man a g e m e n t .


The below is perhaps because you are not in the same domain when you installed
SQLServer.

Login to your computer name from sqlcmd, ie

C:\ >sqlcmd -SMYCOMPUTERNAME\SQLEXPRESS -E -h-1 -y 0

Check your username.

1> select user_name()


2> GO
Guest

Page 22
TAFJ-M S S QL I n s t all

Create a login for your user that must have admin privileges. In this case it is
roderickv

1> CREATE LOGIN [MYCOMPUTERNAME\roderickv] FROM WINDOWS;


2> GO

Check that it worked:

1> SELECT NAME FROM SYS.SERVER_PRINCIPALS


2> GO
sa
public
sysadmin
securityadmin
serveradmin
setupadmin
processadmin
diskadmin
dbcreator
bulkadmin
BUILTIN\Users
L40RB1P1\roderickv
(12 rows affected)

Put sqlserver in single instance mode by starting SQL Server Configuration Manager

Then click on “SQL Server Services”. On the right pane, right click on the SQL Server
running, then “Properties”

Then add –m as a startup property and restart the sql server service once changes are
applied.

Page 23
TAFJ-M S S QL I n s t all

Page 24
TAFJ-M S S QL I n s t all

TAFJ fail s with c# stor e d pro c e d u r e s with


Hos t P r o t e c t i o n E x c e p t i o n .
The error will look like this in the database.log

[ERROR] 2013-04-04 11:25:04,492 [tSA 2_733366180] DATABASE - Error in


executeSQLQueryForXMLSchema: A .NET Framework error occurred during execution of
user-defined routine or aggregate "tafjmatches":
System.Security.HostProtectionException: Attempted to perform an operation that was
forbidden by the CLR host.

The protected resources (only available with full trust) were: All
The demanded resources were: Synchronization

System.Security.HostProtectionException:
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj,
RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)

Page 25
TAFJ-M S S QL I n s t all

at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder


binder, Object[] parameters, CultureInfo culture)
at System.SecurityUtils.ConstructorInfoInvoke(ConstructorInfo ctor, Object[] args)
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType,
String initializeData)
at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.TraceInternal.get_Listeners()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at UserDefinedFunctions.tafjmatches(String sVal1, String sMask)

To fix this:

1) Set appropriate permissions on the DB

a. As master db, give the following permission to your target DB

b. 1> ALTER DATABASE R12GAMBSS SET TRUSTWORTHY OFF;

c. 2> GO

2) Reimport your assembly code

JDBC Driver Fail s With: Fail e d to load th e sqljd b c_ a u t h . d l l or “ This


drive r is not configu r e d for integ r a t e d auth e n ti c a t io n”

This occurs when the jdbc url includes integratedSecurity=true. Either the version of
sqljdbc_auth.dll is incorrect (you are using a 32 bit version on a 64 bit machine or vice versa)
or java is failing to load the sqljdbc_auth.dll

Option 1) set PATH=%PATH%;%TAFJ_HOME%\ext\sqljdbc_1.2\enu\auth\x64 (or x86


depending on your JVM architecture, ie. java -version)

Option 2) Undesirable—Add -Djava.library.path=<<Path where sqljdbc_auth.dll resides>> to


ALL of the batch files in %TAFJ_HOME%\bin

SQLCMD Error s: Fail s to Start

Description: After trying to start sqlcmd it complains with Named Pipe error

C:\data\srcT24\rtc>sqlcmd -h-1 -y 0

HResult 0x2, Level 16, State 1

Page 26
TAFJ-M S S QL I n s t all

Named Pipes Provider: Could not open a connection to SQL Server [2].

Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a
connection to the server. When connecting to SQL Server 2005, this failure may be caused
by the fact that under the default settings SQL Server does not allow remote connections..

Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

Solution: start sqlcmd like this: sqlcmd -S<computerName>\SQLEXPRESS –E

Page 27

You might also like