Hi, Aidy, I tried your way, but failed, you have not provide some method for user id, user password input. Would you please provide the information more detailed?
I find another solution which can well deal with this problem. But I still expect your reply. require 'win32ole' class SqlServer # This class manages database connection and queries attr_accessor :connection, :data, :fields attr_writer :username, :password def initialize(host, username = 'sa', password='') @connection = nil @data = nil @host = host @username = username @password = password end def open(database) # Open ADO connection to the SQL Server database connection_string = "Provider=SQLOLEDB.1;" connection_string << "Persist Security Info=False;" connection_string << "User id...@username};" connection_string << "password...@password};" connection_string << "Initial Catalog=#{database};" connection_string << "Data source...@host};" connection_string << "Network Library=dbmssocn" @connection = WIN32OLE.new('ADODB.Connection') @connection.Open(connection_string) end def query(sql) # Create an instance of an ADO Recordset recordset = WIN32OLE.new('ADODB.Recordset') # Open the recordset, using an SQL statement and the # existing ADO connection recordset.Open(sql, @connection) # Create and populate an array of field names @fields = [] recordset.Fields.each do |field| @fields << field.Name end begin # Move to the first record/row, if any exist recordset.MoveFirst # Grab all records @data = recordset.GetRows rescue @data = [] end recordset.Close # An ADO Recordset's GetRows method returns an array # of columns, so we'll use the transpose method to # convert it to an array of rows @data = @data.transpose end def close @connection.Close end end db = SqlServer.new('localhost', 'user_id', 'user_password') db.open('DB_name') db.query("SELECT * from table_name;") p db.data =begin puts field_names = db.fields cust = db.data puts cust.size puts cust[0].inspect =end db.close Thanks. Wesley Chen. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---