วันศุกร์ที่ 2 พฤศจิกายน พ.ศ. 2555

ขั้นตอนการ Backup Database SQL 2008

1.ไปที่ Start / Program / Microsoft SQL Server 2008 / SQL Server Management
2.Connect to Server ด้วย Server ที่ใช้งาน
3.คลิก ขวา เลือก Base ที่ต้องการ Backup จากตัวอย่าง base ชื่อ dbwins_demo ไปที่ Tasks / Backup
4.หน้าต่าง Back Up Database เลือก Add หากมีข้อมูลค้างที่ช่อง Back Up to ให้เลือก path เก่าแล้วกดที่ Remove ทิ้งก่อน แล้วค่อยกดที่ Add
5.หน้าต่าง Select Backup Destination ช่อง file name เลือก Brow
6.Locate Database เลือกไดร์ ที่จัดเก็บ backup จากภาพเลือก D / ช่อง file name กำหนดชื่อ base ที่ต้องการ backup ตามตัวอย่างภาพ แล้วกด OK
7.เลือก OK
8.หน้าต่างสุดท้ายเลือก OK รอ Progress แสดงผล 100 เปอร์เซ็นต์ backup สำเร็จ

การแบ็คอัพ SQL Database

            ถึงแม้ว่าระบบจัดการฐานข้อมูลของ SQL Server จะมีการทำ Automatic Recovery เมื่อข้อมูลเกิดความเสียหายแล้วก็ตาม ผู้ใช้งานระบบควรต้องมีการแบ็คอัพข้อมูลไว้ด้วยเพื่อความปลอดภัยให้มากยิ่งขึ้น เพราะถ้าการทำ Automatic Recovery ของ SQL Server ไม่สำเร็จ ก็อาจต้องใช้ข้อมูลชุดแบ็คอัพแทน การแบ็คอัพข้อมูลจะสามารถแบ็คอัพดาต้าเบสตั้งแต่ Master,MSDB,Mode,Distribution Database รวมทั้งดาต้าเบสที่ผู้ใช้สร้างขึ้นด้วย การเลือกประเภทของการแบ็คอัพยังขึ้นกับปริมาณข้อมูลด้วย
  1. Full Backup คือ การแบ็คอัพข้อมูลทั้งหมดของดาต้าเบส และบางส่วนใน Transation Log ที่เกิดขึ้นขณะทำการแบ็คอัพ ซึ่งสามารถแบ็คอัพขณะที่ดาต้าเบสกำลังถูกใช้งานอยู่ โดยเมื่อเริ่มทำการแบ็คอัพ SQL Server จะเพิ่มรายการแบ็คอัพนี้ไว้ใน Transation Log เพื่อให้รู้ว่าจุดเริ่มต้นอยู่ที่ใด เมื่อแบ็คอัพส่วนที่เป็นดาต้าเบสเสร็จ ก็จะแบ็คอัพ Transation Log ที่เกิดขึ้น  Full Backup เป็นวิธีการแบ็คอัพที่สะดวก และสามารถนำไปใช้ในการทำแบ็คอัพล่าสุดเท่านั้น การแบ็คอัพวีธีนี้เหมาะสำหรับ Master,MSDB,Model และยูสเซอร์ดาต้าเบสที่ข้อมูลไม่มากนักและใช้เวลาการแบ็คอัพไม่นาน โดยทั่วไปถ้าดาต้าเบสมีขนาดใหญ่มากและอัพเดทบ่อยๆจะใช้ร่วมกับการแบ็คอัพแบบอื่นๆคือ Differential และTransaction Log ทำให้ไม่เสียเวลามากไป และยังได้ข้อมูลที่ใกล้เคียงกับความเป็นจริงมากที่สุด
  2. Differential คือ การแบ็คอัพเฉพาะส่วนที่เป็นข้อมูลที่มีการเปลี่ยนแปลง ดังนั้นถ้ามีการแบ็คอัพแบบ Differrntial ทุกคืน ข้อมูลที่แบ็คอัพในคืนวันพุธจะมีข้อมูลที่มีการเปลี่ยนแปลงของทั้งวันจันทร์และอังคารด้วย เวลาที่จะกู้ข้อมูลก็เพียงแต่นำชุด Full Backup ลงก่อน จากนั้นจึงค่อยนำ Differential Backup ครั้งล่าสุดลงถัดไป
  3. Transaction Log คือการแบ็คอัพเฉพาะส่วนที่เป็น Transaction Log การแบ็คอัพแบบนี้จะใช้เมื่อต้องการแบ็คอัพข้อมูลจนถึงปัจจุบัน เมื่อเสร็จสิ้นการแบ็คอัพนี้แต่ละครั้ง SQL Server จะตัดส่วน (Truncate) ของ Transaction Log ที่สมบูรณ์ไป แล้วนำพื้นที่นี้มาใช้ใหม่เพื่อทำ Transaction Log ครั้งถัดไปช่วยให้ Transaction Log มีขนาดไม่ใหญ่ไป (การทำแบบ Full และ Differential จะไม่ Truncate ส่วน Transaction Log เมื่อจบการแบ็คอัพ) ดังนั้นเมื่อต้องการจะกู้ข้อมูล ก้อจะต้องเริ่มจากการนำ Full Backup หรือ Differential ลงก่อน แล้วจึ่งค่อยทยอยนำ Transaction Log ที่แบ็คอัพไว้แต่ละชุดลงตามลำดับก่อนหลัง ดังตัวอย่าง
                         Time1                                   Full Backup
                         Time2                                   Transaction Log Backup
                         Time3                                   Full Backup
                         Time4                                   Transaction Log Backup
                         Time5                                   System Fail
         
          เมื่อกู้ข้อมูลหลังเวลา Time5 ก็ให้นำ Full Backup ที่เวลา Time3 ลงก่อนจากนั้นค่อยนำ Transaction Log Backup ที่เวลา Time4 ลงแต่เนื่องจาก Log ที่มีในเวลา Time4 นั้นจะเริ่มตั้งแต่หลังจากที่แบ็คอัพ Time2 ซึ่ง่จ่ะคลุม Log ที่ช่วงเวลา Time3 ไปด้วย ดังนั้นจะมีบางส่วนที่ซ้ำกันคือ ช่วง Time2 และ Time3 ทั้งใน Full Backup และ Transaction Log Backup แต่ขณะกู้ข้อมูล SQL Server หากตรวจว่ามีบางส่วนที่ซ้ำกันก็จะข้าม Log ช่วงนั้นใน Transaction Log ไป

    4.   File and Filegroup ในดาต้าซึ่งประกอบไปด้วยไฟล์และไฟล์กรุ๊ปต่างๆ สามารถเลือกที่จะแบ็คอัพแยกแต่ละไฟล์หรือไฟล์กรุ๊ปได้โดยไม่ต้องแบ็คอัพทั้งดาต้าเบส วิธีนี้เหมาะสำหรับดาต้าเบสที่ขนาดใหญ่มากๆและมีเวลาไม่เพียงพอที่จะแบ็คอัพได้หมด หรือมีการแบงดาต้าเบสแยกเก็บไว้ในหลายๆดิสก์ เมื่อมีดิสก์ใดเกิดเสีย ก็กู้ การกู้ไฟล์ก็ยังต้องใช้ชุดแบ็คอัพ Transaction Log ของไฟล์หรือไฟล์กรุ๊ปนั้นลงตามนอกจากว่าข้อมูลในไฟล์หรือไฟล์กรุ๊ปไม่มีการอัพเดท


ข้อจำกัดระหว่างการแบ็คอัพ
แม้ว่าการแบ็คอัพของ SQL Server จะสามารถทำงานได้ขณะที่ยังมีการใช้งาน SQL Server อยู่แต่ก็มีข้อจำกัดบางอย่างไม่ควรกระทำระหว่างการแบ็คอัพ

สำหรับการแบ็คอัพแบบ Full และ Differential สิ่งที่ไม่ควรทำคือ
  1. การจัดการเกี่ยวกับดาต้าเบส ได้แก่ ALTER DATABASE,CREATE DATABASE และ DROP DATABASE
  2. การลดขนาดเนื้อที่ดาต้าเบสด้วยคำสั่ง DBCC SHRINKDATABASE
  3. การสร้างอินเด็กซ์ (เป็นข้อห้ามเฉพาะเมื่อมีการแบ็คอัพดาต้าเบสเท่านั้น)
  4. การใช้คำสั่งที่ไม่มีการบันทึกใน Transaction Log ได้แก่ Balk Copy,SELEC INTO ในกรณีที่คำสั่งนี้กำลังทำงานอยู่ แล้วมีการสั่งแบ็คอัพ SQL Server ก็จะยกเลิกการแบ็คอัพ แต่ในทางกลับกันคือ ถ้ากำลังแบ็คอัพอยู่ แล้วมีการส่งคำสั่งเหล่านี้เข้าไป ก็จะทำการยกเลิกคำสั่งเหล่านั้น

ส่วนการแบ็คอัพแบบ Transaction Log จะไม่เกิดขึ้นมา
  1. กำหนดออปชั่น trunc. Log on chkpt ให้เป็น TRUE ซึ่ง Transaction Log จะถูก Truncate เมื่อเกิด Check Point เท่านั้น
  2. ไม่มีการบันทึกคำสั่งลงใน Transaction Log เลยเพราะเรียกแต่คำสั่งที่ไม่บันทึกลง Transaction Log หลังจากการแบ็คอัพดาต้าเบสครั้งสุดท้าย
  3. มีการเพิ่มหรือลบไฟล์ออกจากดาต้าเบส
  4. Transaction Log ถูก Truncate
การวางแผนการแบ็คอัพ
ชนิดของดาต้าเบส ประเภทและเวลาที่ควรทำแบ็คอัพ
Master ทำ Full Backup และแบ็คอัพเมื่อมีการเรียกคำสั่งที่มีผลต่อ System Table ซึ่งได้แก่คำสั่ง
*เพิ่ม แก้ไข และยกเลิกรหัสล็อคอิน
*CREATE,ALTER และ DROP DATABASE
*CREATER,ALTER และ DROP ไฟล์กรุ๊ปหรือแบ็คอัพดีไวซ์
*เปลี่ยนออปชั่นของเซิร์ฟเวอร์หรือดาต้าเบส
*เพิ่มหรือยกเลิกการลิงค์เซิร์ฟเวอร์
MSDB ทำ Full Backup และควรทำเมื่อ
*สร้างงานที่มีการตั้งเวลาให้ทำงานอัตโนมัติเพราะ MSDB Schedule Task
*มีการทำ หรือปรับแต่งออปชั่นการทำ Replicate
Model ทำ Full Backup และควรทำเมื่อมีการแก้ไขพร็อพเพอร์ตี้ของดาต้าเบสและเมื่อ เพิ่ม แก้ไข หรือยกเลิกอ๊อปเจ็กต์ในดาต้าเบส Model
Distribution เมื่อมีการเปลี่ยนแปลงข้อมูลหรือโครงสร้างของดาต้าเบส
User Database ทำ Full Backup ร่วมกันกับ Differential ควรทำเมื่อสร้างดาต้าเบส เพิ่ม ลบ หรือ เปลี่ยนแปลงโครงสร้างของเทเบิล ข้อมูล รวมทั้งการสร้างอินเด็กซ์

  ตัวอย่างการแบ็คอัพ User Database
      - Full Backup เดือนละครั้ง
      - Differential ทุกอาทิตย์
      - Transction Log ทุกคืน

อ้างอิง http://itd.htc.ac.th/st_it50/it5012/P_2/Implement%20of%20Database/images/B6.htm

Transaction Log และ Check Point กับการกู้ข้อมูล


      Transaction Log (.ldf) คือ log file ที่จะบันทึกคำสั่งของการทำงานรวมถึงการเปลี่ยนแปลงที่เกิดขึ้นกับ database ตั้งแต่ Insert, Update และ Delete และเมื่อถึง Check point ก็จะบันทึกลงใน Database โดย Transition Log จะแยกเก็บเป็น Files ซึ่งเมื่อเขียนจนถึงตำแหน่งสุดท้ายของไฟล์แล้ววนกลับไปที่จุดเริ่มต้นของพื้นที่ว่าง แต่ถ้าไม่มีที่ว่าง Log file ก็จะขยายใหญ่ขึ้นเรื่อยๆ

      Checkpoint จะถูกสร้างโดยอัตโนมัติเมื่อ Transaction log ถูกเขียน record ไปเรื่อยๆ ระยะเวลาหนึ่ง หรือ stop/start sql server instant, backup, alter database

      ทั้ง Transaction Log และ Check Point ถือได้ว่าเป็นบทบาทสำคัญต่อการกู้ข้อมูลเมื่อมีความเสียหายเกิดกับระบบอย่างกะทันหัน และหลังจากสตาร์ทเซอร์วิสของ MSSOL Server ใหม่แล้ว ระบบจัดการฐานข้อมูล (RDBMS) จะทำการกู้ความเสียหายเบื้องต้น โดยจะกู้ดาต้าเบสที่เสียหาย (ถ้ามี) เรียงลำดับ Master,Model,Temp DB,MSDB และดาต้าเบสอื่นๆ เช่น ดาต้าเบสที่สร้างโดยยูสเซอร์ เป็นต้น

ตัวอย่าง






















จากรูปอธิบายได้ดังนี้
1. System Failure เกิดขึ้นที่ T(f) และ Check Point ล่าสุดเมื่อเวลา T(c)
2. Transaction T1 เสร็จสิ้นก่อนเวลาT(c)
3. Transaction T2 เกิดก่อนเวลา T(c) และเสร็จสิ้นหลังเวลา T(c)
4. Transaction T3 เกิดก่อนเวลา T(c) แต่ไม่เสร็จสิ้นหลังเวลา T(c) 5. Transaction T4เกิดก่อนเวลา T(c) และเสร็จสิ้นหลังเวลา T(c)
6. Transaction T2 เกิดก่อนเวลา T(c) แต่ไม่เสร็จสิ้นหลังเวลา T(c)

และหลังจากสตาร์ทเซอร์วิส MSSQL Server ใหม่ได้แล้ว ระบบจะทำการกู้ข้อมูลและตรวจสอบทรานแซคชั่นต่างๆจาก Transaction Log ซึ่งพบว่า
  1. T3 และ T5 จะต้องยกเลิก (Roll Back)
  2. T2 และ T4 จะต้องเข้าไปทำงานใหม่ (Roll Forward) เพราะข้อมูลที่ทำงานตามคำสั่งใน T2,T4 ยังไม่ได้บันทึกลงในดาต้าเบสเท่านั้น
  3. T1ไม่ต้อง Roll Back หรือ Roll Forward เพราะระบบได้ทำการบันทึกข้อมูลของการเปลี่ยนแปลงลงดาต้าเบสเรียบร้อยแล้ว

วันพฤหัสบดีที่ 1 พฤศจิกายน พ.ศ. 2555

ปัญหาขนาด database log file .ldf โตไม่หยุด MSSQL server

file .ldf เป็นไฟล์ที่แยกเก็บบันทึก transaction ของไฟล์ฐานข้อมูล (.mdf file) และจำเป็นต้องใช้งานคู่กัน ถ้าหาก transaction log ไม่สมบูรณ์หรือเราจัดการผิดวิธี sql server จะเรียกใช้งาน database ก้อนนั้นไม่ได้เลย

สาเหตุที่ไฟล์ .LDF ขนาดใหญ่ขึ้นไม่หยุด

ปกติค่า default ของฐานข้อมูลใน SQL server จะอยู่ใน full recovery mode แปลว่าถ้าเราไม่ทำอะไรซักอย่างกับ database ก้อนนี้ ขนาดของไฟล์ .ldf ก็จะโตขึ้นเรื่อยๆ ทุกวันจนฮาร์ดดิสเต็มในที่สุด

ในการติดตั้ง SQL Server ไม่ได้มี options นี้ให้เราเลือก admin หลายคนกด next >> ไปไม่โดยไม่สนใจบางทีก็คิดไปเองว่า การติดตั้ง database ลงในเซอฟเวอร์เป็นหน้าที่ของผู้พ้ฒนาโปรแกรมน่าจะรู้เรื่องมั้ง (พลาดแล้ว..)

วิธีแก้ปัญหาขนาดไฟล์ .LDF


1. ตั้งค่า recovery model ของ database เป็น simple เพื่อให้ database หยุดขยายขนาด log แบบไม่มี limit
  • ใช้ SQL Server Management Studio login เข้าไปจัดการเซอฟเวอร์ฐานข้อมูล
  • ใน Object Explorer browse ไปที่ไฟล์ database ที่ต้องการ Right click > Properties > Options เลือก Rocovery model : Simple





2. ลดขนาดของ log file (.ldf) ที่เกินจำเป็น

Options A: Shink database

  1. เลือกคลิ้กขวาที่ database > Tasks > Shrink > Files
  2. File type: Log
  3. Shrink action : Release unused space
  4. กด OK

Option B: detach/attach สร้าง .ldf log file ใหม่ *ควรจะทำ full backup ไว้ก่อน
เลือกคลิ้กขวาที่ database > Tasks > Detach...
  1. ถ้ามีการใช้งาน database นี้อยู่จะมี Active connections ให้ปิดโปรแกรมที่ใช้งานก่อนติ๊กถูกที่ drop connections กด OK
  2. ลบ หรือ เปลี่ยนชื่อ ไฟล์ ldf เป็นชื่ออื่น
  3. เลือก Tasks > Attach ไฟล์ .mdf เข้าไปใหม่

Recovery model ใน SQL server database


  1. Simple recovery model : เมื่อถึงจุด Checkpoint ระบบจะเคลียร์พื้นทีจาก Record แรกสุด - MinLSN เป็นที่ว่างเขียนทับได้
  2. Full recovery model : records ทั้งหมดจะห้ามเขียนทับจนกว่าเราจะทำ transaction log backup (Manual)
  3. Bulk-logged recovery model : จะสร้าง Checkpoint ทุกครั้งที่เรา backup log หรือทำ bulk-copy


สรุปว่า นอกจาก Simple Recovery model แล้วจะต้องมี admin คอยทำหน้าที่จัดการ backup log file และ Shrink database เป็นประจำนั่นเอง

แต่ Size ของ *.mdf และ *.ldf จะเปลี่ยนแปลงหรือ date modified ก็ต่อเมื่อ SQL close file หรือขยาย size ของ Database หรือ restart service

อ้างอิง : http://msdn.microsoft.com/en-us/library/ms189573.aspx
              http://aifarfa.blogspot.co.uk/2012/02/database-log-file-ldf-mssqlserver.html

วันศุกร์ที่ 26 ตุลาคม พ.ศ. 2555

ConditionEvent Table ของ Factorytalk Alarm Database

ConditionEvent Table

   คือ Table ใน databse AlarmEvent ที่ใช้ในการเก็บ Message Alarm ต่างๆจาก PLC ซึ่งรายละเอียดของแต่ละ field แสดงดังตารางด้านล่าง


Name Data type Description Example
EventID FTUID Unique identifier associated with the record. B281E097-5B7E-4167-A24B-C33BBE412C35
SourceName NVARCHAR The name of the object (up to 200 characters) that generated the event. For condition events, the Source value is generally the alarm name. MixingTank1 System
SourcePath NVARCHAR The FactoryTalk Directory path (ADS path - up to 512 characters) to the Alarm and Event server where the alarm occurred. RNA://$Global/ ApplicationName/Area1/Line1
SourceID1 FTUID Link to object such as equipment or location entry. B281E097-5B7E-4167-A24B-C33BBE412C35
ServerName Nvarchar The name of the alarm server (up to 50 characters). RSLinx Enterprise
TicksTimestamp Bigint Time the event occurred, represented in FileTime format (a 64-bit value consisting of the number of 100-nanosecond intervals since January 1, 1601 UTC). 6.32624E+17
EventTimestamp Datetime Time the event occurred in Greenwich Mean Time (GMT). 10/10/2004 12:00:01 PM
EventCategory NVARCHAR The category to which the event belongs (up to 50 characters). Categories are server defined and can vary depending on the event type. Condition: Level, Deviation, Rate of Change, Discrete
Severity Integer The urgency of the event. This may be a value in the range of 1 - 1000. 700
Priority Integer Enum The priority of the event (Enumeration: 1=Low, 2=Medium, 3=High, 4=Urgent). 4
Message NVARCHAR Message text that describes the event (up to 512 characters). MixingTank1 full
ConditionName NVARCHAR The name of the associated alarm condition (up to 50 characters). LOLO, LO, HI, HIHI, DEV_LO, DEV_HI, TRIP, TRIP_L, ROC_NEG & ROC_POS
SubConditionName2 NVARCHAR The name of the sub-condition associated with the alarm condition (up to 50 characters). LOLO, LO, HI, HIHI, DEV_LO, DEV_HI, TRIP, TRIP_L, ROC_NEG & ROC_POS
AlarmClass NVARCHAR The class name associated with the alarm (up to 40 characters). FTO=Failed To Open, FTC=Failed To Close
Active Bit A value indicating whether or not the alarm is active. True=1, False=0
Acked Bit A value indicating whether or not the alarm has been acknowledged. True=1, False=0
EffDisabled Bit A value indicating whether or not the alarm is effectively disabled. This is the combined effect of the alarm source disable state and the disable states of the areas containing the alarm. True=1, False=0
Tip: You cannot disable areas in FactoryTalk Alarms and Events v2.20.00 (CPR 9).
Disabled Bit A value indicating whether or not the alarm source is disabled. True=1, False=0
EffSuppressed Bit A value indicating whether or not the alarm is effectively suppressed. This is the combined effect of the alarm source suppress state and the suppress states of the areas containing the alarm. True=1, False=0
Tip: You cannot suppress areas in FactoryTalk Alarms and Events v2.20.00 (CPR 9).
Suppressed Bit A value indicating whether or not the alarm source is suppressed. True=1, False=0
PersonID1 VARCHAR An identifier (up to 50 characters) of the component or user that initiated the action resulting in the condition changing state (e.g., acknowledge, disable, suppress). Dave Butler
ChangeMask Integer A value that indicates the properties that have changed in this event (e.g., an alarm could change from normal acknowledged to active unacknowledged). 11
For more information on the specific bit values, see Change Mask Values.
InputValue Real The value of the alarm source. 83
LimitValue Real The limit value that was compared with the alarm source value that triggered the alarm. 80
Quality Integer Indicates the quality of a tag or device upon which the condition is based. Good, Uncertain, Bad
For additional supported values that are not addressed by the OPC DA specification, see Extended Quality Values.
For more information on the meaning of the standard OPC quality values, see the OPC DA specification on the OPC Foundation website.
EventAssociationId FTUID The EventId associated with the current event. Use this field to query for all of the events related to a given instance of an alarm and compute associated information (for example, the length of time that an item was active or active and unacknowledged). B281E097-5B7E-4167-A24B-C33BBE412C35
As a given alarm instance changes state, this ID value will remain constant. For example, when an alarm becomes active, it will be assigned an ID value; when the alarm is acknowledged or returns to normal, that same ID value continues to be logged. Additionally, the same ID will be used for multiple conditions of a level alarm (for example, the HI and HIHI alarms will  use the same ID value since the level alarm does not return to normal when going from the HI to HIHI states).
UserComment 1 NVARCHAR Comment text (up to 512 characters). Inspection OK
UserComputerID1 NVARCHAR Computer name (up to 64 characters). MIXERSTATION
Tag1Value NVARCHAR Value of associated tag 1 (up to 128 characters) 10
Tag2Value NVARCHAR Value of associated tag 2 (up to 128 characters) 10
Tag3Value NVARCHAR Value of associated tag 3 (up to 128 characters) 10
Tag4Value NVARCHAR Value of associated tag 4 (up to 128 characters) 10

Extended Quality Values


The following table describes quality values (in addition to those provided by the OPC DA specification) that are supported by FactoryTalk Alarms and Events.

Quality Value (Decimal)
Display String
Description
192
Good Quality - Non-specific
The quality of the value is good. There are no special conditions.
216
Good Quality - Local Override
The value has been overridden. Typically, this indicates that the input has been disconnected and a manually entered value has been ’r;forced ‘ .
00
Bad Quality - Non-specific
The value is bad, but no specific reason is known.
65536
Bad Quality - Alarm input quality is bad
The alarm instruction input fault has been set to true.
4
Bad Quality - Configuration Error
There is some server-specific problem with the configuration. For example, the item in question has been deleted from the configuration.
1048580
Bad Quality - Severity value is out of valid range (1-1000)
The severity of the alarm condition has been set to an invalid value.
1114116
Bad Quality - Overlapping threshold limits
A limit value of a level alarm has been set to a value that overlaps another limit.
1179652
Bad Quality - Deadband must be greater than or equal to zero
The deadband of a level alarm has been set to a negative value.
1245188
Bad Quality - Rate of change positive limit must be greater than or equal to zero
The positive limit of a rate of change alarm has been set to a negative value.
1310724
Bad Quality - Rate of change negative limit must be greater than or equal to zero
The negative limit of a rate of change alarm has been set to a negative value.
1376260
Bad Quality - Rate of change period must be greater than or equal to zero
The rate of change period has been set to a negative value.
1441796
Bad Quality - The alarm has been deleted
The alarm has been deleted from a controller via an online edit.
8
Bad Quality - Not Connected
The input is required to be logically connected, but it is not. This quality may reflect that no value is available at this time (for example, the value may have not been provided by the data source).
12
Bad Quality - Device Failure
A device failure has been detected.
16
Bad Quality - Sensor Failure
A sensor failure had been detected. Note that the 'Limits' field can provide additional diagnostic information in some situations.
20
Bad Quality - Last Known Value
Communications have failed. However, the last known value is available. Note that the ’r;age ‘ of the value may be determined from the TIMESTAMP in the OPCITEMSTATE.
2162708
Bad Quality - Connection to controller has been lost
The connection to the controller has been lost.
2228244
Bad Quality - A program download is in progress
A program download is in progress.
2293780
Bad Quality - Non-Recoverable Program Fault has occurred in controller
A Major Non-Recoverable program fault has occurred.
24
Bad Quality - Communication Failure
Communications have failed. There is no last known value available.
28
Bad Quality - Out of Service
The block is off scan or otherwise locked. This quality is also used when the active state of the item or the group containing the item is InActive.
2097180
Bad Quality - Unable to subscribe to alarms from controller
If after connecting to a controller, RSLinx Enterprise cannot subscribe to alarms contained in the controller (for example, create the notify object) or can create the notify object, but only succeeds in subscribing to a subset of the total alarms.
32
Bad Quality - Waiting for initial data
After items are added to a group, it may take some time for the server to actually obtain values for these items. In such cases, the client might perform a read (from cache) or establish a connection point-based subscription and/or execute a refresh on such a subscription before the values are available. This sub-status is only available from OPC DA 3.0 or newer servers.
64
Uncertain Quality - Non-specific
The value is uncertain, but no specific reason is known.
68
Uncertain Quality - Last Usable Value
The entity that was writing this value has stopped doing so. The returned value should be regarded as ’r;stale ‘ . Note that this differs from a BAD value with sub status 5 (Last Known Value). That status is associated specifically with a detectable communications error on a ’r;fetched ‘ value. This error is associated with the failure of some external source to ’r;put ‘ something into the value within an acceptable period of time. Note that the ’r;age ‘ of the value can be determined from the TIMESTAMP in OPCITEMSTATE.
2424900
Uncertain Quality - Mode of controller has been changed to Program.
The controller is in Program mode.
2359364
Uncertain Quality - Major Program Fault has occurred in controller
A Major Recoverable program fault has occurred.
80
Uncertain Quality - Sensor Not Accurate
Either the value has ’r;pegged ‘ at one of the sensor limits (in which case the limit field should be set to 1 or 2) or the sensor is otherwise known to be out of calibration via some form of internal diagnostics (in which case the limit field should be 0).
84
Uncertain Quality - Engineering Units Exceeded
The returned value is outside the limits defined for this parameter. Note that in this case (per the Fieldbus Specification), the 'Limits' field indicates which limit has been exceeded but does not necessarily imply that the value cannot move farther out of range.
88
Uncertain Quality - Sub-Normal
The value is derived from multiple sources and has less than the required number of good sources.

วันพุธที่ 24 ตุลาคม พ.ศ. 2555

การ Add และ Restore Database (.bak) ใน SQL Server

1. เปิด Microsoft SQL Server Management Studio
2. Connect SQL ไปยัง Server Name ที่คุณต้องการจะเพิ่ม หรือ Restore Database
3. Click ขวาที่ Database บน Object Explorer แล้วเลือก Restore Database...
4. ที่ช่อง To database : ให้เลือก Database ที่มีอยู่หากต้องการ Restore หรือให้ตั้งชื่อใหม่หากต้องการ Add
5. เลือก Form device : และกดปุ่ม Browse เพื่อเลือก file .bak ที่ต้องการโดยการกดปุ่ม Add
6. เมื่อเลือก file .bak ที่ต้องการแล้วกด OK
7. เสร็จแล้วสามารถลบหรือ replace file .bak ได้

วันจันทร์ที่ 22 ตุลาคม พ.ศ. 2555

การเพิ่ม Tags จาก Control Logix มาเก็บไว้ใน Database ของ FatoryTalk Historian

ค่า Tags จาก PLC (Controller) จะส่งมายัง Data Server (Linx Enterprise) แล้วจึงส่งต่อให้ FTLD Interface เพื่อเก็บค่าลง Database ดังรูป


และเราสามารถปรับแต่งเงื่อนไขในการเก็บข้อมูลลง database ได้เพื่อลดขนาดข้อมูล ได้ดังนี้

1. เลือก Mode ในการเก็บข้อมูล ดังนี้
  1.1 Polled Mode
       - Linx Enterprise จะดึงข้อมูลจาก PLC ตามเวลา Scan rate ที่กำหนดไว้
       - Linx Enterprise จะส่งข้อมูลให้ FTLD ตามเวลา Scan rate ที่กำหนดไว้เหมือนกัน
   โดยให้ทำการกำหนด Location3 = 0 และ กำหนดค่า Scan rate ที่ Location4
  1.2 Advise Mode
      - Linx Enterprise จะดึงข้อมูลจาก PLC ตามเวลา Scan rate ที่กำหนดไว้
      - Linx Enterprise จะส่งข้อมูลให้ FTLD เมื่อค่านั้นมีการเปลี่ยนแปลง
โดยให้ทำการกำหนด Location3 = 1 และ กำหนดค่า Scan rate ที่ Location4

2. กำหนดเงื่อนไขการ Filter ข้อมูล ดังนี้
 2.1 Exception Test จะเก็บข้อมูลเมื่อค่าของ Sample มากกว่าหรือเท่ากับค่า ExcDev หรือเวลาของ Sample มากกว่าเท่ากับค่า ExcMax ดังรูป


ผลที่จะได้

ข้อมูลจาก PLC
ข้อมูลหลังทำ Exception


 2.2 Compression Test จะเก็บข้อมูลเมื่อค่าของ Sample มากกว่าหรือเท่ากับ Comdev หรือเวลาของ Sample มากกว่าเท่ากับค่า Compmax ดังรูป


ผลที่จะได้

ข้อมูลจาก PLC
ข้อมูลหลังทำ Compression
ซึ่งหลังจากที่นำข้อมูลที่ส่งมาจาก PLC ผ่านการทำ Exception และ Compression Test แล้ว ข้อมูลที่จะถูกเก็บใน Historian ก็จะน้อยลง ดังตัวอย่างรูปด้านล่าง

ส่วนการแสดงผลของ Trend บน HMI ก็สามารถปรับเปลี่ยนได้ที่ type ของ Menu Pen

วันเสาร์ที่ 20 ตุลาคม พ.ศ. 2555

การลงโปรแกรม Factorytalk SE 6.0


Factorytalk SE 6.0 จะเป็นโปรแกรมที่รันบน OS 32 bit หรือ 86 bit

ขั้นตอนการลงโปรแกรม Factorytalk SE V6.0

1. ต้องใช้ user ที่เป็น Administrator ของเครื่องที่จะลงโปรแกรม
2. ติดตั้ง Microsoft Internet Information (IIS) ใน Windows Features โดยจะทำการติดตั้ง
    2.1 IIS Metabase and IIS 6 configurationcompatibility
    2.2 ASP และ ISAPI Extension
    2.3 WebDAV Publishing

    ซึ่งจะแสดงตัวอย่างภาพของ Windows7 และ Windows Server2008


Windows 7

Windows Server 2008



3. เปิด Program install และเลือก Install Factory Talk View Site Edition จะปรากฎหน้าต่างด้านล่าง


4. หากเคยลงโปรแกรม Factorytalk มาก่อนให้เลือก Uninstall FactoryTalk View Site Edition
5. Install FactoryTalk Service Platform ซึ่งเป็นส่วนที่ทำหน้าที่ติดต่อกับ Windows
6. Install FactoryTalk View Site Edition ซึ่งเป็นส่วนที่ใช้ในการ Modify HMI และให้ใส่ Product's Serial Number:0123456789 
   และระหว่าง install จะมี message windows ถามว่าคุณได้ติดตั้ง IIS แล้วหรือยัง หากคุณได้ติดตั้งแล้วในหัวข้อที่ 2. ให้กด OK


   ก่อนที่จะเสร็จสิ้นขั้นตอนนี้ ระบบก็จะถามหา Computer ที่เก็บตัว HMI Project ที่คุณต้องการ Run ซึ่งถ้าหากเครื่องที่กำลังติดตั้งเก็บ HMI Project เองก็ให้กำหนดเป็น This Computer หรือ localhost  แต่ถ้าหากเป็น Network และตัว HMI Project เก็บไว้เครื่องอื่นก็ให้เข้าไปเลือกที่ปุ่ม ... ซึ่งในรูปตัวอย่างเครื่อง Server ชื่อ rbf_l1srv01 จะเก็บ HMI Project ไว้



This Computer (Local)

Network
  จากนั้นก็ให้ restart computer
7. Install RSLinx Enterprise เพื่อใช้ในการติดต่อกับ PLC ของ Rockwell รุ่น Logic5000 เป็นต้นไป และยังสามารถสร้าง Database เพื่อเก็บ Alarm ต่างๆได้
8. Install RSLinx Classic เพื่อใช้ในการติดต่อกับ PLC ของ Rockwell หรือสามารถติดต่อกับ PLC ยี่ห้อได้โดยใช้ Protocal DH เป็นต้น

Code VB สำหรับส่ง Mail ทาง Outlook

Code VB สำหรับส่ง e-mail และ Attach file ด้วย Outlook ที่คุณมี user อยู่ โดยตัวอย่าง จะส่ง e-mail และ file Test.xlsx ไปยัง To และ Cc.  x.automation2012@gmail.com ซึ่งกำหนดไว้ 2 เงื่อนไข คือ
- Show หน้าต่างของ e-mail เพื่อให้กดปุ่ม Send : ให้เลือก .Display
- ส่ง e-mail ทันที: ให้เลือก .Send

ซึ่งเนื่องจากเราจะส่ง e-mail ผ่านทาง Outlook ดังนั้นเราจึงต้องเพิ่ม Microsoft Outlook Component ให้กับ VB Project ก่อนที่จะ Coding โดยให้เพิ่ม "Microsoft Outlook 12.0 Object Library" ดังรูป



ตัวอย่างของโปรแกรม โดยเลือกส่ง e-mail ทันที
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim oapp As Outlook.Application
    Dim oEmail As Outlook.MailItem
   
    Set oapp = New Outlook.Application
    Set oEmail = oapp.CreateItem(olMailItem)
 
    On Error GoTo SendEmailErr
    With oEmail
       .To = "x.automation2012@gmail.com"
       .CC = "x.automation2012@gmail.com"
       .Subject = "Energy Planing"
       .BodyFormat = olFormatPlain
       .Body = "Test"
       '.Importance = olImportanceHigh
       .ReadReceiptRequested = True
       .Attachments.Add "D:\Test.xlsx", olByValue
       .Recipients.ResolveAll
       .Save
       '.Display 'Show the email message and allow for editing before sending
       .Send 'You can automatically send the email without displaying it.
    End With
    Set oEmail = Nothing
    'oapp.Quit
    Set oapp = Nothing
   
Exit_SendEmail:
    Set oEmail = Nothing
    Set oapp = Nothing
    Exit Sub
   
SendEmailErr:
    MsgBox "Error " & Err.description
    Resume Exit_SendEmail
End Sub

รวบรวม Script ที่ใช้ในการติดต่อ Database แบบต่างๆ

SQL Server  ODBC Standard Security: "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;" 
Trusted connection: "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" 
Prompt for username and password: oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;" 
OLE DB, OleDbConnection (.NET) Standard Security: "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
Trusted connection: "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
Prompt for username and password: oConn.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Data Source=Aron1;Initial Catalog=pubs;" 
SqlConnection (.NET) Standard Security: "Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
Trusted connection: "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
Access  ODBC Standard Security: "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;" 
Workgroup: "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;SystemDB=C:\mydatabase.mdw;","admin", "" 
Exclusive: "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Exclusive=1;Uid=admin;Pwd=" 
OLE DB, OleDbConnection (.NET) Standard Security: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=asdasd;" 
Trusted connection: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;","admin", "" 
Prompt for username and password: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;","admin", "" 
Oracle  ODBC New version: "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" 
Old version: "Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;" 
OLE DB, OleDbConnection (.NET) Standard security: "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;" 
Trusted Connection: "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;" 
OracleConnection (.NET) Standard: "Data Source=Oracle8i;Integrated Security=yes"; 
MySQL  ODBC Local database: "Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;" 
Remote database: "Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;" 
OLE DB, OleDbConnection (.NET) Standard: "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;" 
MySqlConnection (.NET) eInfoDesigns.dbProvider: "Data Source=server;Database=mydb;User ID=username;Password=pwd;Command Logging=false" 
DSN  ODBC DSN: "DSN=myDsn;Uid=username;Pwd=;" 
File DSN: "FILEDSN=c:\myData.dsn;Uid=username;Pwd=;" 
Excel  ODBC Standard: "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\MyExcel.xls;DefaultDir=c:\mypath;" 
OLE DB Standard: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
Text  ODBC Standard: "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\txtFilesFolder\;Extensions=asc,csv,tab,txt;" 
OLE DB Standard: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""