Showing posts with label ive. Show all posts
Showing posts with label ive. Show all posts

Monday, March 26, 2012

Read Text File from SQL Server, Read its content, and load it in RichTextBox (Related comp

OBJECTIVE: I would like to read a text file from SQL Server 2000, read the text file content, and load its conntents in a RichTextBox

THINGS I'VE DONE AND HAVE WORKING:
1) I've successfully load a text file (ex: textFile.txt) in sql server database table column (with datatype Image)

2) I've also able to load the file using a Handler as below:

using System;
using System.Web;
using System.Data.SqlClient;

public class HandlerImage : IHttpHandler {

string connectionString;
public void ProcessRequest (HttpContext context)
{
connectionString = System.Configuration.ConfigurationManager.ConnectionStrings
["NWS_ScheduleSQL2000"].ConnectionString;
int ImageID = Convert.ToInt32(context.Request.QueryString["id"]);
SqlConnection myConnection = new SqlConnection(connectionString);

string Command = "SELECT [Image], Image_Type FROM Images WHERE Image_Id=@.Image_Id";
SqlCommand cmd = new SqlCommand(Command, myConnection);
cmd.Parameters.Add("@.Image_Id", System.Data.SqlDbType.Int).Value = ImageID;

SqlDataReader dr;

myConnection.Open();
cmd.Prepare();
dr = cmd.ExecuteReader();
if (dr.Read())
{ //WRITE IMAGE TO THE BROWSER
context.Response.ContentType = dr["Image_Type"].ToString();
context.Response.BinaryWrite((byte[])dr["Image"]);
}
myConnection.Close();
}

public bool IsReusable {
get {
return false;
}
}

}'>'>

<ahref='<%# "HandlerDocument.ashx?id=" + Eval("Doc_ID") %>'>

File

</a>
- Click on this link, I'll be able to download or view the file

WHAT I WANT TO DO, BUT HAVE PROBLEM:
- I would like to be able to read CONTENT of this file and load it in a string as below

StreamReader SR = new StreamReader()
SR = File.Open("File.txt");
String contentText = SR.Readline();
txtBox.text = contentText;

BUT THIS ONLY WORK FOR files in the server.
I would like to be able to read FILE CONTENTS from SQL Server.

PLEASE HELP. I really appreciate it.

I've figured it out, but it takes too long for my browser to load, and end up with string that include many squares like "Submitted 22155 1966 Servers".

Below is my code that goes with what is above.

Stream theFile =newMemoryStream((byte[])dr["Doc"]);

StreamReader SR =newStreamReader(theFile);

String contentText = SR.ReadToEnd();

If anybody can tell me why it's so slower to load the content of the text file on browser compare to uploading it to the database, and a way to speed it up

I'll really appreciate it.

Thanks,

Friday, March 23, 2012

Read log files

hi,
how do i read the transaction log file. Actualy i've got a database given my some 1 else, we do not have the db diagrams and no relationship between the tables and no source code, can we find out that when the front end application updates the tables, wh
ich are the table where entries r made? I wanted to use that data futher?...
Check out Lumigent's "Log Explorer" product - it's built for performing log
analysis etc.
www.lumigent.com
Regards,
Greg Linwood
SQL Server MVP
"sim sim" <sim sim@.discussions.microsoft.com> wrote in message
news:73057BCA-FDEB-4D07-B5DA-40867DE76678@.microsoft.com...
> hi,
> how do i read the transaction log file. Actualy i've got a database given
my some 1 else, we do not have the db diagrams and no relationship between
the tables and no source code, can we find out that when the front end
application updates the tables, which are the table where entries r made? I
wanted to use that data futher?...
>
|||hi Greg,
thanks 4 the reply, but this site give a 3rd party software 2 do the same... can't we read the log file without this. or is there any way by which i can find which tables are getting updated by recent transactions.
regards,
"Greg Linwood" wrote:

> Check out Lumigent's "Log Explorer" product - it's built for performing log
> analysis etc.
> www.lumigent.com
> Regards,
> Greg Linwood
> SQL Server MVP
> "sim sim" <sim sim@.discussions.microsoft.com> wrote in message
> news:73057BCA-FDEB-4D07-B5DA-40867DE76678@.microsoft.com...
> my some 1 else, we do not have the db diagrams and no relationship between
> the tables and no source code, can we find out that when the front end
> application updates the tables, which are the table where entries r made? I
> wanted to use that data futher?...
>
>
|||You might consider running a Profiler trace to track application activity.
This can be saved to a table for subsequent analysis.
Hope this helps.
Dan Guzman
SQL Server MVP
"sim sim" <simsim@.discussions.microsoft.com> wrote in message
news:266C54C8-505E-46BF-8CFB-4C55C6838D40@.microsoft.com...
> hi Greg,
> thanks 4 the reply, but this site give a 3rd party software 2 do the
same... can't we read the log file without this. or is there any way by
which i can find which tables are getting updated by recent transactions.[vbcol=seagreen]
> regards,
>
> "Greg Linwood" wrote:
log[vbcol=seagreen]
given[vbcol=seagreen]
between[vbcol=seagreen]
made? I[vbcol=seagreen]
|||Hi Dan
Thanks a lot u'r suggestion was of great help. Can u suggest some site where i can get good help on making use of the SQL Profiler.
Regards
"Dan Guzman" wrote:

> You might consider running a Profiler trace to track application activity.
> This can be saved to a table for subsequent analysis.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "sim sim" <simsim@.discussions.microsoft.com> wrote in message
> news:266C54C8-505E-46BF-8CFB-4C55C6838D40@.microsoft.com...
> same... can't we read the log file without this. or is there any way by
> which i can find which tables are getting updated by recent transactions.
> log
> given
> between
> made? I
>
>
|||I suggest you start with the Books Online
<adminsql.chm::/ad_mon_perf_88c3.htm>. You can save the results to a table
for ad-hoc analysis. The events of interest here are the 'completed' events
for batches and RPCs. You can also add sp:statement completed if needed.
Hope this helps.
Dan Guzman
SQL Server MVP
"sim sim" <simsim@.discussions.microsoft.com> wrote in message
news:9BF8F3EE-D25B-4089-9E4D-9B34CB99BF69@.microsoft.com...
> Hi Dan
> Thanks a lot u'r suggestion was of great help. Can u suggest some site
where i can get good help on making use of the SQL Profiler.[vbcol=seagreen]
> Regards
>
> "Dan Guzman" wrote:
activity.[vbcol=seagreen]
the[vbcol=seagreen]
transactions.[vbcol=seagreen]
performing[vbcol=seagreen]
database[vbcol=seagreen]
end[vbcol=seagreen]

Wednesday, March 21, 2012

Read and write a Constraint or Default Value

Okay, maybe I'm getting ahead of myself.

Using SQL Server Express, VWD and .net 2.0 I've figured out how to drop a Table Column Constraint or Default Value/Binding and then Create it again using a stored procedure. What I can't figure out is how to retrieve that column's constraint value and write it to, say a label, in an aspx page, simply for reference. Is it possible? In this case the Data Type of the column is money.

I'm using it to perform a calculation to a column with a value that the user inserts into another column. (Column1(user input) minus Column2(with Default Value) = Column3(Difference). I just want to read Column2's Default Value for reference so I know whether to change it or not.

Tables have Check Constraints, Columns do not.

Open up the Master database and take a look inside.

You are looking for the INFORMATION_SCHEMA views.

In particular, you want this one: INFORMATION_SCHEMA.CHECK_CONSTRAINTS and INFORMATION_SCHEMA.COLUMNS

|||

If I open dbo.tbl1 in my database and right click to modify, I can put a Default Value or Binding of 1000000.00(or whatever) in a column I've named "Gen_ourlim". When I do that, there is, in the folder "Constraints" under dbo.tbl1, something created called DF_tbl1_Gen_ourlim. When I drop that Default Value from column "Gen_ourlim" the DF_tbl1_Gen_ourlim goes away in the Constraint folder. That's why I called the column having a constraint I suppose. In any case, how can I read that Default Value and write it to a web page?

|||

Did you query INFORMATION_SCHEMA.COLUMNS?

The default value is a column in that view, as is the catalog name, the schema name, the table name and the column name. Plus lots of other goodies about a column.

Querying data and placing it on a web page is an entirely different discussion and belongs in one of the web forums.

|||

Thanks David,

Got it. At least I was able to query it:

USE <path to database>

SELECT Column_Name, Column_Default

frominformation_schema.columnswhere table_name='tbl1'and Column_name='Gen_ourlim'

|||

Then you need to mark this thread as resolved, mark answers as appropriate, and start a new thread in a nore appropriate forum on how to put data on a web page.

(But the internet is chock full of how-to articles on that, and any beginner asp.net book will tell you how also. Best to start doing it and ask specific questions when you get stuck.)

|||

Will do David. Thanks again. Using the query in VWD is the easy part. Put the Select in a stored procedure in your Database Explorer as such:

ALTER PROCEDURE dbo.GetDefaultValue

AS
SELECT COLUMN_NAME, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME ='tbl1') AND (COLUMN_NAME = 'Gen_ourlim')
RETURN

Put a SqlDataSource on your page along with a DataView and then configure it to use the stored procedure as the Select in the SqlDataSource. There's a nice little video tutorial on doing this at

http://www.asp.net/learn/sql-videos/video-114.aspx

sql