2018年11月25日 星期日

Docker connect sql server by sqlcmd

env: CentOS 7
        Docker docker-ce-18.05.0.ce
        SQL Server 2017 Linux

當我們在docker啟動SQL Server 2017容器,嘗試使用sqlcmd連線SQL Server。

1.檢查docker上process執行狀態
command:
sudo docker ps -a
找到一個container id:3a5e5ff26d9d 的SQL Server
[root@localhost ~]# sudo docker ps -a

CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS                    PORTS                    NAMES

3a5e5ff26d9d        microsoft/mssql-server-linux:2017-latest   "/opt/mssql/bin/sqls…"   2 hours ago         Up 4 seconds              0.0.0.0:1433->1433/tcp   sqlenterprise

2.在已經安裝好sqlcmd的本機機器進行連線(連線本機的SQL Server in docker)
command:
sqlcmd -S 0.0.0.0,1433 -U sa -P 'Passw0rd@1234'
 
[oracle@localhost ~]$ sqlcmd -S 0.0.0.0,1433 -U sa -P 'Passw0rd@1234'
1> select @@servername
2> go
--------------------------------------------------------------------------------------------------------------------------------
3a5e5ff26d9d                                                                                                                    

(1 rows affected)


3.嘗試使用docker本身提供的ip進行連線SQL Server
command:
sqlcmd -S 172.17.0.2,1433 -U sa -P 'Passw0rd@1234'

[oracle@localhost ~]$ sqlcmd -S 172.17.0.2,1433 -U sa -P 'Passw0rd@1234'
1> select @@servername
2> go
--------------------------------------------------------------------------------------------------------------------------------
3a5e5ff26d9d                                                                                                                   
(1 rows affected)

1> exit
*因為我們在建立SQL Server容器並沒有提供特定ip,所以SQL Server的ip是docker網卡提供的ip
當時使用的指令如下:
 
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passw0rd@1234' \
-p 1433:1433 --name sql1 \
-d microsoft/mssql-server-linux:2017-latest

 

Docker install sql server 2017

env: CentOS 7
        Docker docker-ce-18.05.0.ce
        SQL Server 2017 for Linux

可以參考:
https://hub.docker.com/r/microsoft/mssql-server-linux/
https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017

1.透過docker指令下載SQL Server 2017 image
command:
sudo docker pull microsoft/mssql-server-linux:2017-latest


[root@localhost ~]# sudo docker pull microsoft/mssql-server-linux:2017-latest
2017-latest: Pulling from microsoft/mssql-server-linux

f6fa9a861b90: Pull complete

da7318603015: Pull complete

6a8bd10c9278: Pull complete

d5a40291440f: Pull complete

bbdd8a83c0f1: Pull complete

3a52205d40a6: Pull complete

6192691706e8: Pull complete

1a658a9035fb: Pull complete

103fa96eca85: Pull complete

4105e5c7e280: Pull complete

Digest: sha256:4ef33b1d0b2f264550c152e24a87322daae40b090d3ba32f1241cb0fd4510421

Status: Downloaded newer image for microsoft/mssql-server-linux:2017-latest
[root@localhost ~]#

2.確認下載的docker image
command:
docker image ls

[root@localhost ~]# docker image ls

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE 
microsoft/mssql-server-linux   2017-latest         bbe2822dfe38        33 hours ago        1.43GB

hello-world                    latest              e38bc07ac18e        6 weeks ago         1.85kB
[root@localhost ~]#

3.開始使用image建立container
指定image "microsoft/mssql-server-linux:2017-latest"建立container名稱為"sql1"
sa的密碼指定為"Passw0rd@1234"
command:
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passw0rd@1234' \
 -p 1433:1433 --name sql1 \
 -d microsoft/mssql-server-linux:2017-latest

[root@localhost ~]# sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passw0rd@1234' \

>    -p 1433:1433 --name sql1 \

>    -d microsoft/mssql-server-linux:2017-latest

c6bdad51c6d288836e00bd116ceb1386732bb78331d817973b8b16e1cc9c9f6c
[root@localhost ~]#

4.檢查建立的container
command:
sudo docker ps -a

[root@localhost ~]# sudo docker ps -a

CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS                     PORTS               NAMES
c6bdad51c6d2        microsoft/mssql-server-linux:2017-latest   "/opt/mssql/bin/sqls…"   3 minutes ago       Exited (1) 3 minutes ago                       sql1


出現Exited (1) 3 minutes ago 主要原因是記憶體不足2GB,請將主機記憶體加到2GB。
執行以下指令停止重啟container即可。
c6bdad51c6d2是container id
command:
docker restart c6bdad51c6d2


 

oracle sqlplus connect to cloud database

env: Oracle Linux 6
        Oracle 12c
        Windows 10(本地電腦)

如何透過在本地端使用SQLPLUS連線到ORACEL Cloud

1.首先在Oracle Cloud要設定對外ip與防火牆,這必須在Oracle Cloud的管理頁面設定,並且在本地端安裝sqlplus client。 
2.獲取Oracle service namea.可以在tnsnames.ora找到servicename
b.使用指令"lsnrctl status"也可以得到資訊







並且在本地端tnsnames.ora進行設定。
1.service_name可以依照自己喜好輸入取代
2.aaaaaa為Oracle Cloud的server name

service_name =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = aaaaaa.oraclecloud.internal)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = aaaaaa.oraclecloud.internal)



3.在本地端電腦host加入record。主要讓電腦可以認得Oracle Cloud的ip跟server name

 


4.透過SQLPLUS連線到Oracle Cloud
command:

 
 


2018年11月24日 星期六

linkedserver and MSDTC

env: Windows server 2012R2
        SQL Server 2008R2

這次嘗試施做Linkedserver與MSDTC

首先我們先準備2台server,本次沒有加入網域
1.WIN-QH8BBS4P9J9
2.WIN-TKJM6HAMBVJ

1.在WIN-TKJM6HAMBVJ建立Linkedserver到WIN-QH8BBS4P9J9























2.利用powershell啟用MSDTC
Add-WindowsFeature Application-Server, NET-Framework-45-Core,
AS-WS-Atomic, AS-Outgoing-Trans, AS-Incoming-Trans 



3.設定MSDTC內容


































4.透過Linkedserver與MSDTC複製資料到本地端SQL Server


begin distributed transaction 

insert into [WIN-QH8BBS4P9J9].test.dbo.tb1

select * from [WIN-TKJM6HAMBVJ].test.dbo.tb1

delete from test.dbo.tb1

commit transaction



2018年11月23日 星期五

sql server linkedserver Invalid connection string attribute

env: SQL Server 2016

在已經建立好的Linkedserver進行遠端查詢,出現以下錯誤訊息:
 Msg 18456, Level 14, State 1, Line 1

Login failed for user 'aaaaa'.
OLE DB provider "SQLNCLI11" for linked server "sssss" returned message "Invalid connection string attribute".

經過檢查Linkedserver可以連通伺服器,帳號密碼正確

Linkedserver的設定是透過連線字串指定帳號與db name,如下圖


  




檢查本地端與目的端伺服器發現,兩端的同一名稱的帳號密碼不同。
解決方式: 將兩端帳號密碼設定相同,並且修改Linkedserver密碼即可正確執行。





2018年11月18日 星期日

sql server linkedserver query error 7416

env: SQL Server 2016

透過Linkedserver進行查詢出現查詢結果不一致的狀況:
1.用sa查詢可以順利產出結果
2.用一般帳號出現以下錯誤

Query view via linkedserver with error by user:
Msg 7416, Level 16, State 2, Line 1
Access to the remote server is denied because no login-mapping exists..

Linkedserver設定內容








從上圖可以看到是連線字串格是錯誤,造成一般帳號查詢出現錯誤。
解決方式:調整連線字串內容即可。










2018年11月13日 星期二

oracle soa login plugin db


oracle_soa_login_plugin_db

env: Oracle 12c

Oracle 12c 開始有Pluggable database, 在Oracle Cloud for SOA也開始使用
Oracle Pluggable database與SQL Server  Containser DB有異曲同工之妙

Login Oracle Pluggable database
command:

step1: login Oracle by sqlplus

[oracle@B2B ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Tue Nov 7 10:18:45 2017

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Connected to:

Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production

SQL>

step2: list pluggable database
SQL> select pdb from v$services;

PDB------------------------------
B2BPDB
CDB$ROOT
CDB$ROOT
CDB$ROOT
CDB$ROOT


step3: swith session and connect to plugged database
SQL> alter session set container=B2BPDB;
 
Session altered.
step4: list pluggable database
SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
TEMP
USERS
SP954682_IAS_UMS

5 rows selected.
 

2018年11月11日 星期日

oracle soa db exp

env: Oracle Cloud 12c


因為問題需要把Oracle Cloud SOA DB做export備份,出現下面訊息

command:
exp aaaaa/bbbbb@B2BTPDB file=/u03/app/oracle/fast_recovery_area/OECB2BT/soalob.dmp log=/u03/app/oracle/fast_recovery_area/OECB2BT/soalob.log tables=SP954682_DBFS.SHARE buffer=1000000 feedback=10000

msg:
Connected to: Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)


About to export specified tables via Conventional Path ...
Current user changed to SP954682_DBFS
EXP-00111: Table SHARE resides in an Encrypted Tablespace SP954682_DBFS and will not be exported
EXP-00008: ORACLE error 6550 encountered
ORA-06550: line 1, column 14:
PLS-00201: identifier 'SYS.DBMS_DBFS_SFS_ADMIN' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
EXP-00085: The previous problem occurred when calling SYS.DBMS_DBFS_SFS_ADMIN.instance_info_exp for object 98776
Export terminated successfully with warnings.

這個問題主要在於SOA的Tablespace是壓縮的,導致傳統的export無法使用。

可以使用下面的指令查看Tablespace使否是壓縮的:
command:
select tablespace_name, bigfile, encrypted from dba_tablespaces;


TABLESPACE_NAME                BIG ENC
------------------------------ --- ---
SYSTEM                         NO  NOSYSAUX                         NO  NO
TEMP                           NO  NO
SP65647288_IAS_TEMP            NO  NOSP65647288_STB                 NO  YES
SP954682_DBFS                YES YES



把傳統的export指令改為10g以後推出的expot data pump就可以了
command:
expdp aaaaa/bbbbb@B2BTPDB tables=SP954682_DBFS.SHARE directory=soadmp dumpfile=soalob.dmp logfile=soalob.log

msg:
Export: Release 12.1.0.2.0 - Production on Sun Oct 15 10:45:05 2017
Copyright (c) 1982, 2015, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production

Starting "aaaaa"."SYS_EXPORT_TABLE_01":  aaaaa/********@B2BTPDB tables=SP954682_DBFS.SHARE directory=soadmp dumpfile=soalob.dmp logfile=soalob.log

Estimate in progress using BLOCKS method...

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 57.43 GB
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled