Writer Block Reader, Reader Block Writer...

Sep 27, 2005

hi,

i've performed a test on 2 machines based on the topic above, but it doesn't seem like blocking each other... This is the context...

I've created a table call TEST_DEL i.e.
quote:CREATE TABLE test_del
(v_id INT,
desc CHAR(3)
)

In machine 1, i'm login as USER 1 and try to insert a set of records into the table
quote:
Machine 1
~~~~
BEGIN
DECLARE @li_num int,
@li_start int

SET @li_num = 100000
SET @li_start = 1

WHILE @li_start < @li_num
BEGIN
INSERT INTO test_del VALUES (@li_start, 'zzz', 'xxx')

IF (@li_start > @li_num)
BREAK
ELSE
SET @li_start = @li_start + 1
CONTINUE

END
END




In machine 2, i login in as USER 2 to retrieve the records at the same time...
quote:
SELECT * FROM test_del


but, the system still allow me to retrieve the records at the same time... May i know when will "Writer block reader, reader block writer" occur and in what situation

Thanks in advance

View 1 Replies


ADVERTISEMENT

SqlDataReader Reader Connection Closing Before Dt.Load(reader)

Jun 26, 2007

As you see in the images the connection is closing. During the read it counts 5 columns which is correct. When I step through the code it closes the connection when it hits dt.Load(reader) and nothing is loaded into the datatable.
 
------------------------------------------------------------AS I STEP THROUGH -----------------------------------------------------------------------------------------------------------------------

 
Please help,
 
Thanks,
Tom

View 1 Replies View Related

T-SQL (SS2K8) :: Why Block Scope Variables Exist Outside Of Block

Dec 3, 2014

I have the following stored procedure to test scope of variables

alter proc updatePrereq
@pcntr int,
@pmax int
as
begin

[Code] ....

In the above script @i is declare in the if block only when the @pcntr value is 1. Assume the above stored procedure is called 5 times from this script

declare @z int
set @z = 1
declare @max int
set @max = 5
while @z <= @max
begin
exec dbo.updatePrereq @z, @max
set @z = @z + 1
end
go

As i said earlier `@i` variable exists only when `@pcntr` is `1`. Therefore when i call the stored procedure for the second time and so forth the control cannot enter the if block therefore @i variable wouldn't even exist. But the script prints the value in `@i` in each iteration, How comes this is possible should it throw an error saying `@i` variable does not exist when `@pcntr` values is greater than `1`?

View 1 Replies View Related

Report Writer

Jan 25, 2008

Does anyone alot about microsoft report writer?

View 2 Replies View Related

SQL Writer Error

Apr 8, 2007

I have received the following error just yesterday and again today.

"SQL Writer" "Library Failed Installation".



It states I need to uninstall the program and reinstall it. I have never enountered this before. Help!



View 1 Replies View Related

Writer Role: Db_dtsadmin But Where And How?

Jul 19, 2006

I'd like to grant this role to a domain user. But I don't see how.

tia

View 2 Replies View Related

Backup SQL Using MSDE Writer

Jan 19, 2007

How do I backup my SQL Databases using MSDE Writers?

I do not see MSDE Writers under NT Backup.

Thanks

Santhosh

View 1 Replies View Related

Microfosoft SQL Server VSS Writer

Aug 29, 2007


Hi There, Don't know if im in the right place but I couldn't quite find what I was looking for.


Anyway yesterday by mistake I started to uninstall/remove Microsoft SQL Server VSS Writer by mistake. I cancelled it quite quickly so it didn't completely uninstall, but now im getting this message when turning on my computer:

SQL Server
Your SQL Server installation is either corrupt or has been tampered with ( Could not open SQLEVN70.RLL). Please uninstall then re-run setup to correct this problem.


The other message I get is when I am turning off my computer this one says:

End Program - WDS _ SL
This program is not responding.
To return to Windows and check the status of the program click cancel.
If you choose to end the program now click end.

My guess is that both messages are relatated to the same problem.

Can someone help me solve this problem?

View 4 Replies View Related

Will The Developer Licence Of SQL Get The Report Writer

Jan 28, 2004

I just heard of the new report writer feature in SQL. Will it be available for use in the developer edition.

View 1 Replies View Related

Using Report Writer For Access Database

Jul 11, 2007

Hi,

Can I use any existing MS report writer for Access database?

Thanks

View 8 Replies View Related

Log Reader

Aug 22, 2007

We dont want to use triggers or replication to capture changes in a set of tables; we have the same problem in Oracle and we use LogMiner to do so. We have been looking for similar tools in SQL Server but the ones we have found so far dont seem to fulfill our requirements (Redgate and Lumigent).
Does anyone know any other third party application that can read a SQL Server log and extract changes filtering by table name?

Thanks.

View 1 Replies View Related

Pl/Sql Block?

Apr 8, 2008

I've written a couple blocks but I have no idea when it comes to this one.
Create a PL/SQL block to retrieve the last name and department ID if each employee from the EMPLOYEES table
for those employees whose EMPLOYEE_ID is less than 114. From the values retreived from the employees table, populate two PL/SQL tables,
one to store the records of the employee last names and the other to store the records of their department IDs.
Using a loop, retreive the employee name information and salary infromation from the PL/SQL tables and doisplay it in the window,
using DBMS_OUTPUT.PUT_LINE. Display these details for the first 15 employees in the PL/SQL tables.
Any help helps

View 1 Replies View Related

AES (128 Bit Block) : Can I Use It?

May 18, 2006

If I've got a 64-bit OS such as Windows XP Professional x64 Edition running and I have the SQL Server 2005 Express Edition, is AES permittable or does TRIPLEDES still need to be used?

View 1 Replies View Related

Data Reader ?

Sep 24, 2007

is it possible to use a data reader to read from 2 tables with 1 store procedure(sp)?
 -------------------------------------------------
ex:
create sp1
as 

select * from tbl1
select * from tbl2
 -------------------------------------------------
 how can i use a data reader to read the items from tbl2?
 

 
 

View 5 Replies View Related

Data Reader

Feb 22, 2008

Hi Guys,I have a quick question about DataReader, I have a function called "ExportTotal" i am calling this function from another function. what it does is it will put the Total for each Network in the Line 34. Right now what it is doing is It is putting the First Networktotal,2ndNetwork total,3rdNetwork total....... in the line 34. what i want is if the control comes to first network then it has to put only 1st network total and for the 2nd network only 2nd network total and so on. Please see my function below. Can you guys tell me what i am doing wrong?ThxPrivate Function exporttotal() As String Dim sql As String Dim dbFunctions As New DatabaseUtilities Dim tempinvoicetotal As String 'Dim rateactuals As String Dim filetext As String Dim tempclientname As String Dim strconn As String Dim prev_network As String = "" Dim current_network As String = "" strconn = CONNECTIONSTRING sql = "SELECT CAST(SUM(tblSpot.rateActual) AS int(4)) AS Rateactuals, SUM(tblSpot.rateActual * 0.85) AS netrate, SUM(tblSpot.rateActual * 0.15) AS commrate,TBLCLIENT.CLIENTNAME " & _"FROM tblSpot INNER JOIN tblContract ON tblSpot.fkContract = tblContract.pkid INNER JOIN " & _ " tblClient ON tblContract.fkClient = tblClient.pkid WHERE tblSpot.fkContractType = 'UNWIRED' AND " & _ "fkInvoiceNumber = '" & Me.txtinvoicenumber.Text & "' GROUP BY TBLCLIENT.CLIENTNAME" Dim myConn As New SqlConnection(CONNECTIONSTRING) Dim myCommand As New SqlCommand(sql, myConn) myConn.Open() Dim dbreader As SqlDataReader = myCommand.ExecuteReader() While dbreader.Read() Try Dim Rateactuals As String If dbreader("Rateactuals") Is DBNull.Value Then Rateactuals = "" Else Rateactuals = dbreader("Rateactuals") tempinvoicetotal = Rateactuals End If Dim clientname As String If dbreader("clientname") Is DBNull.Value Then clientname = "" Else clientname = dbreader("clientname") tempclientname = clientname End If If prev_network = "" Then filetext = filetext & vbCr & "34;;" & tempinvoicetotal & "00" & ";"Session("EDIExport4") = filetext prev_network = tempclientname Else current_network = tempclientname If prev_network <> current_network Then filetext = filetext & vbCr & "34;;" & tempinvoicetotal & "00" & ";"Session("EDIExport4") = filetext prev_network = tempclientname Else End If End If Catch SqlEx As SqlClient.SqlException Session("Error") = SqlEx.Message.ToString Response.Redirect("Error.aspx?Form=" & Request.Path) Catch Ex As System.Exception Session("Error") = Ex.Message.ToString Response.Redirect("Error.aspx?Form=" & Request.Path) End Try dbFunctions = Nothing End While myConn.Close() End Function

View 7 Replies View Related

ADO.net (how To Close A Reader)

Nov 29, 2005

Hello, I'm trying to run the following snippet as Console app, and I get an error: "a reader is already open for this connection, and should be closed first" I tried to manually say: SqlDataReader.Close() in the begining of the code, but still get the error, Any suggecstions how to manually close the reader? thank you ---------- here's the code -----------using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; namespace ADO.NET { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { SqlConnection cn = new SqlConnection ("SERVER=MyServer; INTEGRATED SECURITY=TRUE;" + "DATABASE=AdventureWorks"); SqlCommand cmd1 = new SqlCommand ("Select * from HumanResources.Department", cn); cmd1.CommandType = CommandType.Text; try { cn.Open(); SqlDataReader rdr = cmd1.ExecuteReader(); while (rdr.Read()) { if (rdr["Name"].ToString() == "Production") { SqlCommand cmd2 = new SqlCommand("SELECT * FROM " + "HumanResources.Employee WHERE DepartmentID = 7", cn); cmd2.CommandType = CommandType.Text; SqlDataReader rdr2 = cmd2.ExecuteReader(); while (rdr2.Read()) { } rdr2.Close(); } } rdr.Close(); } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { cn.Close(); } } } }

View 2 Replies View Related

Problems With More Than 1 Reader

Mar 13, 2006

Dim conn As SqlConnection = Nothing
Dim cmd As SqlCommand
Dim cmd2 As SqlCommand
try
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("myConnection").ConnectionString)
conn.Open()
cmd = New SqlCommand
cmd.Connection = conn

cmd2 = New SqlCommand
cmd2.Connection = conn
dim reader As SqlDataReader = cmd.ExecuteReader
Right this works and I can access reader fine
but as soon as I do the following I get an error
reader2 = cmd2.ExecuteReader (reader2 is already declared just not put on here)
the error is "There is already an open DataReader associated with this Command which must be closed first."
which is odd because there sqlcommand used for reader2 is different.
Can I not use more than one reader at anyone time? I used to have loads of recordsets open in asp 3 no prob.
Cheers

View 3 Replies View Related

Datasource Reader

Apr 28, 2008

I am trying to do incremental extract using Datasource reader.
I need to send a variable in where condition to extract the data base on the max date from other table.


To implement this i have created two variables
1)to get the max date from the table.
2)to store the sql query and send the mad date from other variable to extract the data.

i have give this sql variable in data flow expression.but its not working.

can any one tell me where i am going wrong.

View 2 Replies View Related

Log Reader Internal

Apr 26, 2007

MY Current database in SIMPLE recoverey model



I have set up the transactional replication. MY log reader process wakes up and runs every 5 min. Does my transactions will get deleted or they still in log file as active even it is in simple recover model.



Logreader how it reads the Transaction log files .? I observed today we are running some big reports. those reports uses INSERT INTO FROM <TABLE > this process showing in DBCC OPENTRAN

MY log reader keep on reading the log file.. it did not come out from that five min duration...



Can someone from the MS share the what /how exactly log reader works ( inside details)

I would like to add more details



The Log Reader Agent is scanning the transaction log for commands to be replicated. Approximately 30500000 log records have been scanned in pass # 3, 1696 of which were marked for replication, elapsed time -623164036 (ms).

The Log Reader Agent is scanning the transaction log for commands to be replicated. Approximately 31000000 log records have been scanned in pass # 3, 1713 of which were marked for replication, elapsed time -177869239 (ms).

everytiome counter startwith 500000 records and keegoing for some time and it is delivering the transactions never stopping the job

Why elpse time is in negative?



How to understan

Do you guys think it is really sc



Thanks

Srini

View 25 Replies View Related

Database Block

Apr 10, 2008

Hello,

I have been experiencing a lot of blocking activity in my database. My trace results show that the following extended stored procedures sp_prepexec and sp_cursorfetch are executed by both the user causing the block and the user tha is blocked. Any ideas as to how to rectify this situation will be appreciated.

Regards,

Albert

View 3 Replies View Related

Try.. Catch Block

Dec 11, 2006

HI,
i'm trying to execute some sql using the Try.. Catch blocks.

Following code does not execute in Catch Block

Begin
begin try
insert into dbo.Test values (1,'aaa')
-- here we are inserting int value in identity field...
END TRY
Begin catch
PRINT 'TEST'
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() as ErrorState,
ERROR_PROCEDURE() as ErrorProcedure,
ERROR_LINE() as ErrorLine,
ERROR_MESSAGE() as ErrorMessage;
END Catch
End
GO


Whereas the following block works fine and the Catch block executes.

Begin
begin try
Select 1/0
--This causes an error.
END TRY
Begin catch
PRINT 'TEST'
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() as ErrorState,
ERROR_PROCEDURE() as ErrorProcedure,
ERROR_LINE() as ErrorLine,
ERROR_MESSAGE() as ErrorMessage;
END Catch
End
GO





Any idea why is it so?

View 5 Replies View Related

How To Check Block

Mar 5, 2008

Can anyone guide me to write check block in SQL Server?
I Mean if blocking occurs, just inform people.

View 3 Replies View Related

Table Block

Mar 18, 2008

Hi there! I need such thing: I have a data in Table A. When I get this data, I also increment this data by one, what I want is block Table A in order to other people will not get access to data.. I think about transactions, but are transactions reaaly blocks a table's content?
P.S. For example in MySQL there are Lock table command for blocking table for reading/writing. I need such thing/
Thanks

View 8 Replies View Related

Process Block Itself

Jul 3, 2007

Hi to everybody,

i have this problem.

sometimes a process in my SQL Server 2005 (upd 2) is blocked from itself. If I find in monitor it wait for a lock_M_Sch_M on a temporary table as you can see from

select * from sys.dm_tran_locks where request_session_id=51 and request_status <> 'GRANT'



resorce type : OBJECT

resource id : 218899226

request mode : Sch-M

request status WAIT

request_session id : 51

request life time : 33554432



or from

SELECT * FROM sys.dm_os_waiting_tasks WHERE SESSION_ID=51



waiting task address : 0x0000000000C2F198

session id : 51

wait type : LCK_M_SCH_M

resource address : 0x0000000201C71300

blocking task address : 0x0000000000C2F198

blocking session id = 51

resource description objectlock lockPartition=0 objid=218899226 subresource=FULL dbid=2 id=lock80d04900 mode=Sch-S associatedObjectId=218899226



I resolve this problem only with restart of sql server . that clear tempdb and eliminate this process



I think is not a problem about latch present from sql server 2000 sp4 (I read some document abount this problem)



So I haven't idea how to resolve this problem and how to kill this kind of process without to restart sql server



thanks in advance



Luca







View 4 Replies View Related

How Do We Use Block Cursor

Oct 25, 2007



hi there,
to retrieve more then one record with a cursor we can use block cursor, so we have to set the cursor attribute SQL_ATTR_ROWSET_SIZE to some number...i am not getting any code example on this.
do anyone know this???

View 6 Replies View Related

Try Catch Block

Apr 12, 2006

Hi:

one of our study group members noticed a strange behavior and has the following question. Any thoughts are appreciated.
I am unable to understand as to why the CATCH block is not executed when an INSERT is made
On table T3 which is dropped after the first transaction.

The severity of Insert into t3 values (3) is Msg 208, Level 16, State 1, Line 2
Invalid object name 't3'.

BOL says TRY€¦CATCH constructs do not trap the following conditions:
Warnings or informational messages with a severity of 10 or lower.
Errors with severity of 20 or higher that terminate the SQL Server Database Engine task processing for the session. If an error occurs with severity of 20 or higher and the database connection is not disrupted, TRY€¦CATCH will handle the error.


Here is the script.




use tempdb
go

create table t1 (a int)
create table t2 (b int)
create table t3 (c int)


Begin tran

Insert into t1 values (1)
Insert into t2 values (2)
Insert into t3 values (3)

IF @@error <> 0
Rollback tran
else
commit tran
-------------------------------------------------------------

Select * from t1
Select * from t2
Select * from t3
-------------------------------------------------------------

Drop table t3

-------------------------------------------------------------

Set xact_abort on
Begin try
Begin tran insertNow

Insert into t1 values (1)
Insert into t2 values (2)

save tran insertNow

Insert into t3 values (3)
commit tran insertNow
End try

Begin Catch

IF (XACT_STATE()) = -1
BEGIN
PRINT 'The transaction is in an uncommittable state.' +
' Rolling back transaction.'
ROLLBACK TRANSACTION insertNow
END;

-- Test if the transaction is active and valid.
IF (XACT_STATE()) = 1
BEGIN
PRINT 'The transaction is committable.' +
' Committing transaction.'
COMMIT TRANSACTION insertNow
END

End Catch



View 9 Replies View Related

Sqldata Reader Question

Jul 18, 2006

Hi,
I am trying to creating an application using C# where I read data from a SQL server. In the database, I have two tables. One that has the Order info and other table has the item info for each of the rows in the Order table. In my application I am run a query and open up a datareader to read in the Order info. While OrderInfoDataReader is still open, I run another query to get the ItemInfo and open another data reader. Well, ADO.Net does not allow two datareader be open at the same time.
My question, what would be a way around to solve the issue? I would greatly appreciate your help.
Thanks,
Emon.

View 1 Replies View Related

Help Retreving Value Form Sql Reader

Aug 18, 2006

hello,
 
I have tried myReader.GetSqlString, GetSqlValue, GetSqlInt16, etc...etc...
But I keep getting an error (System.InvalidCastException was caught  Message="Conversion from type 'SqlInt32' to type 'String' is not valid."  Source="Microsoft.VisualBasic"  StackTrace:       at Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value)       at ImportDelimitedFile.SumCurrentAmount() in C:Documents and Settingsemg3703My DocumentsVisual Studio 2005EscuelasComunidadImportDelimitedFile.aspx.vb:line 556)
 
Here is my code:
 Public Function SumCurrentAmount() As String        Dim sqlconn As New SqlConnection(ConfigurationManager.ConnectionStrings("GDBRemitanceConnectionString1").ConnectionString)        Dim sqlcmd As New SqlCommand("SELECT SUM(CONVERT (Int, Field_6)) AS TotalAmount, Record_Type FROM tblTempWorkingStorage_NACHA GROUP BY Record_Type HAVING (Record_Type = '6')", sqlconn)        Try            sqlcmd.Connection.Open()            Dim myReader As SqlDataReader            myReader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)            If myReader.Read() Then                SumCurrentAmount = CType(myReader.GetSqlValue(0), String)                Return SumCurrentAmount            Else            End If            myReader.Close()        Catch        End Try        sqlcmd.Connection.Close()    End Function
 
I need to know which "GetSql...(type) should I used to extract field numbre one from myReader.
 
Thanks a lot,

View 1 Replies View Related

Data Reader Problem

Jun 11, 2007

Hi All,
   I got an error while running this code.There is already an open DataReader associated with this Command which must be closed first
  How can I resolve the error?
 
protected void Page_Load(object sender, EventArgs e)    {        string sql;                SqlConnection Connection = new SqlConnection("ConnectionString");        sql = "SELECT PO_SE_Line_ID  FROM  PO_STOCK_QUERY_LINE_DETAILS WHERE TRANS_NUM ='TR-A-00-01-93'";
        SqlCommand command = new SqlCommand(sql, Connection);        SqlDataReader Dr;        Connection.Open();        Dr = command.ExecuteReader();                                while (Dr.Read())                {
 sql = "SELECT SUPPLIER_ITEM_CODE,SUPPLIER_MAN_DESC,SUPPLIER_PAT_DESC,SUPPLIER_ITEM_DESC,SUPPLIER_ADDIT_DESC,SUPPLIER_SUGG_RETAIL FROM PO_STOCK_QUERY_LINE_DETAILS where TRANS_NUM ='TR-A-00-01-93' and PO_SE_Line_ID=" + Dr["PO_SE_Line_ID"].ToString();
               SqlCommand command1 = new SqlCommand(sql, Connection);
               SqlDataReader Dr1;
                   
                    Dr1 = command1.ExecuteReader();                                        while(Dr1.Read())                    {
 
                    Response.Write(Dr["SUPPLIER_ITEM_CODE"].ToString());                    Response.Write("<br>");                    Response.Write(Dr["SUPPLIER_MAN_DESC"].ToString());                    Response.Write("<br>");                    Response.Write(Dr["SUPPLIER_PAT_DESC"].ToString());                    Response.Write("<br>");                    Response.Write(Dr["SUPPLIER_ITEM_DESC"].ToString());                    Response.Write("<br>");                    Response.Write(Dr["SUPPLIER_ADDIT_DESC"].ToString());
      }Dr1.Close();
     }Dr.Close();
 
I tried to close the first data reader before opening the second data reader.still the error persists.

View 5 Replies View Related

Data Reader Problem

Jun 26, 2007

Hi, i dont know whats gone wrong! but all of a sudden it seems to be throwing an error, i have looked at my previous code and it matches exactly when it was working, here is the code below int i = 0;for (i = 1; i <= 3; i++)
{
 
//This gets the stock ID from the textbox.string stock_ID = ((TextBox)Panel1.FindControl("txtID" + i.ToString())).Text;
 
//This is the sql statement.string sql = "SELECT [n_or_sh], [title], [cost_price], [selling_price] FROM tbl_stock WHERE stock_ID = " + stock_ID;
 
//This creates a sql command which executes the sql statement.SqlCommand sqlCmd = new SqlCommand(sql, myConn);
myConn.Open();
//This is a reader for the results to go in.SqlDataReader dr = sqlCmd.ExecuteReader();
//This reads the first result from the sqlReader
dr.Read();
//This sets the title label text to the value of the description column.TextBox currentBox1 = (TextBox)Panel1.FindControl("txtDesc" + i);
string strtxtDesc = currentBox1.Text;strtxtDesc = dr["title"].ToString();
 
 
};
myConn.Close();
i = 0;
 
the error its throwing is this
CS1519: Invalid token '(' in class, struct, or interface member declaration for the line myConn.Open()
does anybody have any idea how to solve this?
Jez

View 4 Replies View Related

Coexisting SQL Reader && UPDATE

Aug 17, 2007

In my current application, I have an administration form that fills in labels and checked states via data entered into the database using a similar user input field. What the admin page does is it first lists all the record names in a listview, then on select, it fills in the form based on what the records contain. This means labels text change, and check states change based on the string "True" or "False". This was done using the SQL Reader command.
 Within the same form, the read checkboxes are editable via the admin. When the admin edits the controls, he will click the update button at the bottom and the database will UPDATE .. WHERE UserName = (Scalar for ListBox1.SelectedValue)
I've used the exact same UPDATE command in my form for the user, except the only difference was @ the WHERE clause-- I had it updating based on a GUID. I know my SQL statement is correct, but it just won't update the data.
Is it possible that the READER, which starts (and closes) on pageload cannot coexist within the same form as the UPDATE code?
My code is incredibly long, so for the purposes of a short post I'm not including any bit of it-- but if you would like to see it, just let me know.

View 5 Replies View Related

Sqldatareader Within A Loop From Another Reader?

Dec 26, 2007

I have an SqlDataReader which loops through records returned from an SP, within that loop I would like to initiate another SP, but for some darn reason the following code won't work: // create SqlConnection object
string ConnectionString = ConfigurationManager.ConnectionStrings["aiv3cs"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);

try
{
// Create a new XmlTextWriter instance
XmlTextWriter writer = new
XmlTextWriter(Server.MapPath("products.sitemap"), Encoding.UTF8);

writer.WriteStartDocument();
writer.WriteStartElement("siteMap");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/AspNet/siteMap-File-1.0");

// create the command
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;

// set up the command
myCommand.CommandText = "spGetMenuStructure";
myCommand.CommandType = CommandType.StoredProcedure;

// open the connection
myConnection.Open();

// run query
SqlDataReader myReader = myCommand.ExecuteReader();

bool HasSubElements = false;

SqlCommand myCommand2 = new SqlCommand();
SqlParameter myParameter1 = new SqlParameter();
SqlDataReader myReader2 = new SqlDataReader();

// parse the results
while (myReader.Read())
{
// create the command
myCommand2.Connection = myConnection;

// set up the command
myCommand2.CommandText = "spGetMenuSubElements";
myCommand2.CommandType = CommandType.StoredProcedure;

myParameter1.ParameterName = "@ContentID";
myParameter1.SqlDbType = SqlDbType.Int;
myParameter1.Value = Convert.ToString(myReader["ID"]);

myCommand2.Parameters.Add(myParameter1);

// run query
myReader2 = myCommand2.ExecuteReader();

while (myReader2.Read())
{
HasSubElements = true;
}

myReader2.Close();

if (Convert.ToString(myReader["HasPage"]) == "1")
{
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("title", Convert.ToString(myReader["PageTitle"]));
writer.WriteAttributeString("description", Convert.ToString(myReader["PageTitle"]));

string PageURL = Convert.ToString(myReader["PageName"]) + "?ContentID=" + Convert.ToString(myReader["ID"]);

writer.WriteAttributeString("url", PageURL);

if (HasSubElements)
{
writer.WriteEndElement();
}
}
else
{
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("title", Convert.ToString(myReader["PageTitle"]));
writer.WriteAttributeString("description", Convert.ToString(myReader["PageTitle"]));
}

HasSubElements = false;
}

myReader.Close();

// end the xml document and close
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}

finally
{
myConnection.Close();
}I've gotten the following two errors:There is already an open DataReader associated with this Command which must be closed first.And a build error:Error29The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined Any suggestions would be most appreciated.    

View 4 Replies View Related

Data Reader Question

Feb 11, 2008

Hi Guys,I have a quick question about DataReader, I have a function called "ExportTotal" i am calling this function from another function. what it does is it will put the Total for each Network in the Line 34. Right now what it is doing is It is putting the First Networktotal,2ndNetwork total,3rdNetwork total....... in the line 34. what i want is if the control comes to first network then it has to put only 1st network total and for the 2nd network only 2nd network total and so on. Please see my function below. Can you guys tell me what i am doing wrong?ThxPrivate Function exporttotal() As String Dim sql As String Dim dbFunctions As New DatabaseUtilities Dim tempinvoicetotal As String 'Dim rateactuals As String Dim filetext As String Dim tempclientname As String Dim strconn As String Dim prev_network As String = "" Dim current_network As String = "" strconn = CONNECTIONSTRING sql = "SELECT CAST(SUM(tblSpot.rateActual) AS int(4)) AS Rateactuals, SUM(tblSpot.rateActual * 0.85) AS netrate, SUM(tblSpot.rateActual * 0.15) AS commrate,TBLCLIENT.CLIENTNAME " & _"FROM tblSpot INNER JOIN tblContract ON tblSpot.fkContract = tblContract.pkid INNER JOIN " & _ " tblClient ON tblContract.fkClient = tblClient.pkid WHERE tblSpot.fkContractType = 'UNWIRED' AND " & _ "fkInvoiceNumber = '" & Me.txtinvoicenumber.Text & "' GROUP BY TBLCLIENT.CLIENTNAME" Dim myConn As New SqlConnection(CONNECTIONSTRING) Dim myCommand As New SqlCommand(sql, myConn) myConn.Open() Dim dbreader As SqlDataReader = myCommand.ExecuteReader() While dbreader.Read() Try Dim Rateactuals As String If dbreader("Rateactuals") Is DBNull.Value Then Rateactuals = "" Else Rateactuals = dbreader("Rateactuals") tempinvoicetotal = Rateactuals End If Dim clientname As String If dbreader("clientname") Is DBNull.Value Then clientname = "" Else clientname = dbreader("clientname") tempclientname = clientname End If If prev_network = "" Then filetext = filetext & vbCr & "34;;" & tempinvoicetotal & "00" & ";"Session("EDIExport4") = filetext prev_network = tempclientname Else current_network = tempclientname If prev_network <> current_network Then filetext = filetext & vbCr & "34;;" & tempinvoicetotal & "00" & ";"Session("EDIExport4") = filetext prev_network = tempclientname Else End If End If Catch SqlEx As SqlClient.SqlException Session("Error") = SqlEx.Message.ToString Response.Redirect("Error.aspx?Form=" & Request.Path) Catch Ex As System.Exception Session("Error") = Ex.Message.ToString Response.Redirect("Error.aspx?Form=" & Request.Path) End Try dbFunctions = Nothing End While myConn.Close() End Function

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved