Sie sind auf Seite 1von 24

TAFJ-M S S QL I n s t all

R16
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
th
14 29 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

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

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.
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)

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

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

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:

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

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

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

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

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 21
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 22
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 23
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 24

Das könnte Ihnen auch gefallen