Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'tiny_tds'
- require 'csv'
- ## Connect to database
- client = TinyTds::Client.new username: '<db-user>', password: '<db-password>', host: '<host or IP>', port: 1433, database: '<db-name>'
- if client.active?
- puts "Connection established"
- end
- ## Open and readCSV file
- logs = CSV.read('test.csv')
- ## Store basic information
- host = logs[2][0]
- domain = logs[1][1]
- type = logs[1][2]
- server_type = logs[1][3]
- ## Insert Host information to database and test by verifying the generated index number for the entry
- results = client.execute("INSERT dbo.Host_Name (Host_Name)
- OUTPUT INSERTED.Host_Name_Index VALUES ('#{host}' )")
- results.each do |row|
- puts row
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement