TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Boblysan
NA
66
0
DataReader and ODBC, help please...
Feb 14 2005 11:22 AM
Good morning, I am trying to create a very simple program which pulls information from a DB and populates the information in to a datagrid / table / listview, etc. (I haven not decided which one I am going to use yet) I am able to do this but am getting an odd error which I would like some help with. I can successfully connect to the data source, run a query, etc. The problem is that once I read the information I then attempt to close the reader and it failes. The code!!! private void Form1_Load(object sender, System.EventArgs e) { // Build a connection and SQL strings string connectionString = "DSN=MMB"; string SQL = "select mb_agent_id, mb_agent_name, status, reason, status_change from mb.t_mb_agent where status <> 'DISCONNECTED'"; // Create a connection object OdbcConnection conn = new OdbcConnection(connectionString); // Create a command object OdbcCommand cmd = new OdbcCommand(SQL); OdbcDataReader reader = cmd.ExecuteReader(); cmd.Connection = conn; // Open connection conn.Open(); try { while (reader.Read()) { listView1.Items.Add(reader.GetInt32(0) } } catch (OdbcException err) { MessageBox.Show("ERROR: " + err.Message); } reader.Close(); conn.Close(); } } } When getting to the line reader.Close(); I get a compile time error indicating that the ODBC connection / data source does not support this function. I am using the ODBC.NET component for my project. So I guess I have 2 questions. Is it bad if I do not close the reader but just close the connection instead? Secondly, if my goal is to go grab information from this db every 5 to 10 seconds, should you open the connection once when starting the application and then close it when done? Or should you open and close the connection for every interval I retrieve data? Please advise.. Oh, if you are wondering, the database type I am using is a memory resident db called TimesTen. Thank you,
Reply
Answers (
2
)
Compare Table With Query
webapplication using ADO.NET,C Sharp,OleDb,Ms Access,ASP.NET