473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# database access

(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

Aug 17 '06 #1
5 4013
Currently reading "New to C# - DB question" just posted.

-Markus_R

MarkusR wrote:
(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
Aug 17 '06 #2
Markus,

It doesn't appear to me that the bottleneck is in the code you
provided. I think we'd need to see the contents of the stored
procedure and the schema of your database. Looking up a record among
500,000 in an well indexed table should be nearly instantaneous. If
you do suspect the problem is on the database side (which I do at this
point) then it might be better to post this question in a SQL Server
group.

Brian

MarkusR wrote:
(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
Aug 18 '06 #3
Thanks Brian,

I will look into the schema.

-Markus

Brian Gideon wrote:
Markus,

It doesn't appear to me that the bottleneck is in the code you
provided. I think we'd need to see the contents of the stored
procedure and the schema of your database. Looking up a record among
500,000 in an well indexed table should be nearly instantaneous. If
you do suspect the problem is on the database side (which I do at this
point) then it might be better to post this question in a SQL Server
group.

Brian

MarkusR wrote:
(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
Aug 18 '06 #4
I wouldnt suggest returning a value without closing the record set or
database connection :)
Check out my implementation of ODBC, SqlClient and OleDb connections
using a generic wrapper:

http://www.ziggyware.com/readarticle.php?article_id=38

Altho it will not help in the specific problem you are facing in the
performance of your stored procedure, it will help in managing the
state of the database connection and allow you to have multiple
DataReader's returned.

There are other articles on my site as well if you are interested in
checking them out.

Thanks,
Ziggy

www.ziggyware.com
MarkusR wrote:
Thanks Brian,

I will look into the schema.

-Markus

Brian Gideon wrote:
Markus,

It doesn't appear to me that the bottleneck is in the code you
provided. I think we'd need to see the contents of the stored
procedure and the schema of your database. Looking up a record among
500,000 in an well indexed table should be nearly instantaneous. If
you do suspect the problem is on the database side (which I do at this
point) then it might be better to post this question in a SQL Server
group.

Brian

MarkusR wrote:
(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
Aug 19 '06 #5
Thanks Ziggy,

I do close the database and reader.

What else do I need to close?

-Markus_R

zi*******@gmail.com wrote:
I wouldnt suggest returning a value without closing the record set or
database connection :)
Check out my implementation of ODBC, SqlClient and OleDb connections
using a generic wrapper:

http://www.ziggyware.com/readarticle.php?article_id=38

Altho it will not help in the specific problem you are facing in the
performance of your stored procedure, it will help in managing the
state of the database connection and allow you to have multiple
DataReader's returned.

There are other articles on my site as well if you are interested in
checking them out.

Thanks,
Ziggy

www.ziggyware.com
MarkusR wrote:
Thanks Brian,

I will look into the schema.

-Markus

Brian Gideon wrote:
Markus,
>
It doesn't appear to me that the bottleneck is in the code you
provided. I think we'd need to see the contents of the stored
procedure and the schema of your database. Looking up a record among
500,000 in an well indexed table should be nearly instantaneous. If
you do suspect the problem is on the database side (which I do at this
point) then it might be better to post this question in a SQL Server
group.
>
Brian
Aug 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sarah Tanembaum | last post by:
I was wondering if it is possible to create a secure database system using RDBMS(MySQL, Oracle, SQL*Server, PostgreSQL etc) and web scripting/programming language(Perl, PHP, Ruby, Java, ASP, etc)...
3
by: cooldv | last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and Access 2000 database. (with a hosting company) traffic is slow at this time but expect to grow. lately i have been reading...
10
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network...
5
by: premmehrotra | last post by:
I currently have a multi-user access database which is put on a shared drive L: on a Windows Servers. Entire database is one file premdb.mdb. Users access this database from their laptops....
8
by: John Baker | last post by:
Hi: I am URGENTLY in need of some book or web site OR tool that will help me integrate a relatively simple access application into a web page or pages. This is a time recording system (by...
1
by: Claus Haslauer | last post by:
Hi, firstly, I am new to access03 and server03 Originally, I had written an access 2002 database. Then, we transferred (for another reason) to server 2003. Then, we got access 2003. Then I...
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
7
by: Allison | last post by:
Hi -- we are a small manufacturing looking for a multi-user database to take customer orders (nothing too complicated, with 3 users total). We think we should be using Access, but are wondering...
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
21
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and view records for others. I want to know a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.