M
MarkusR
(VS2005/C#/MSSQL)
I am looking for a very efficient way to do a database lookup.
I am reading 1 to many files in a given directory. I then look up the
information based on the filename into a SQL Server database. There
might be currently only 5 files in my directory but my table may have
500,000+ records. I do not want to cache the data locally, of course.
The following method is too slow:
private int GetFileStatus(string aFilename)
{
SqlConnection Conn;
SqlDataReader reader = null;
Conn = new SqlConnection("user id=myuser;"+
"password=mypwd;" +
"server=myserver;" +
"database=mydatabase;" +
"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd = new SqlCommand("sp_GetFileID", Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new SqlParameter("@filename", aFilename));
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
return Convert.ToInt32(reader[0].ToString());
}
else
return 0;
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}
Obviously I am new to c# database programming.
What is the best way to point to a table and locate the record base on
the filename?
Thanks
-Markus_R
I am looking for a very efficient way to do a database lookup.
I am reading 1 to many files in a given directory. I then look up the
information based on the filename into a SQL Server database. There
might be currently only 5 files in my directory but my table may have
500,000+ records. I do not want to cache the data locally, of course.
The following method is too slow:
private int GetFileStatus(string aFilename)
{
SqlConnection Conn;
SqlDataReader reader = null;
Conn = new SqlConnection("user id=myuser;"+
"password=mypwd;" +
"server=myserver;" +
"database=mydatabase;" +
"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd = new SqlCommand("sp_GetFileID", Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new SqlParameter("@filename", aFilename));
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
return Convert.ToInt32(reader[0].ToString());
}
else
return 0;
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}
Obviously I am new to c# database programming.
What is the best way to point to a table and locate the record base on
the filename?
Thanks
-Markus_R