Advertisement
Guest User

Untitled

a guest
Jul 8th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. require 'tiny_tds'
  2. require 'csv'
  3.  
  4. ## Connect to database
  5. client = TinyTds::Client.new username: '<db-user>', password: '<db-password>', host: '<host or IP>', port: 1433, database: '<db-name>'
  6.  
  7. if client.active?
  8. puts "Connection established"
  9. end
  10.  
  11. ## Open and readCSV file
  12.  
  13. logs = CSV.read('test.csv')
  14.  
  15. ## Store basic information
  16. host = logs[2][0]
  17. domain = logs[1][1]
  18. type = logs[1][2]
  19. server_type = logs[1][3]
  20.  
  21. ## Insert Host information to database and test by verifying the generated index number for the entry
  22. results = client.execute("INSERT dbo.Host_Name (Host_Name)
  23. OUTPUT INSERTED.Host_Name_Index VALUES ('#{host}' )")
  24. results.each do |row|
  25. puts row
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement