Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts

Wednesday, March 21, 2012

listbox contents to sql stored procedure command parameter?

Hello,

Stuck in a spot and hoping someone will nudge me in the right direction...

I'm trying to write to a sql db via a storedprocedure using a parameter. i'm pretty certain the below statement is causing the problem. but i'm not sure how to properly refer to it...

Dim connString As String
connString = "integrated security=false;user id=sa;server=HCENT1;database=LicenseRenewal;persist security info=False"
Dim myConnection As New SqlConnection(connString)
Dim myCommand As New SqlCommand("InsertPage1", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
' ......other (working) parameter statements.......
Dim parameterDates As New SqlParameter("@.Dates", SqlDbType.VarChar, 4000)
parameterDates.Value = Session("lstDates")
myCommand.Parameters.Add(parameterDates)

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

the session("lstDates") is the contents of lstDates.Items (listbox) from a previous page.
i'm guessing its not valid to refer to it as a varchar, can someone point me to the proper way to handle this?

tia
andyI would try Session("lstDates").ToString(), though I personally would try and debug it to see what exactly is in that session variable.

Are you getting an error message? If so, please give the EXACT message.|||thank you for the suggestion.

I've tried what you're saying and the table gets populated with the string:

"System.Web.UI.WebControls.ListItemCollection"

i took a stab in the dark and tried varbinary (sans .tostring) as the sqldatatype for the parameter/storedprocedure/columntype and i received:


Server Error in '/NET/LicenseRenewal' Application.
------------------------

Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object must implement IConvertible.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Object must implement IConvertible.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
LicenseRenewal.W4.WriteDBPage1() in C:\Documents and Settings\andrzej\VSWebCache\www.aea13.org\NET\LicenseRenewal\W4.aspx.vb:453
LicenseRenewal.W4.btnDONE_Click(Object sender, EventArgs e) in C:\Documents and Settings\andrzej\VSWebCache\www.aea13.org\NET\LicenseRenewal\W4.aspx.vb:158
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277

Seems it can't automatically convert a collection of listbox items into a sql column list, a string list (not one long string however) in the column would be sufficient.

i welcome/appreciate any further input.

thank you
andy|||forgot to say, the contents of the session("lstDates") are various quantities (less then 25 typically) of strings following the 'syntax' of "02/02/04 From: 08:00 AM To 09:00 AM". The string gets compiled from a text box and 2 other listboxes and added to the lstDates. I know the session("lstDates") holds valid data because i've used the session info to reload the listbox without problems

http://www.aea13.org/net/licenserenewal/w1p2.aspx is the page that has the listbox, the page following that is supposed to write to the database when someone clicks on the bottom button.

I took copies of these 2 pages out of the full application, spliced them together and have butchered the code to get rid of non (error) relevant functions. only the relevant parts work for this testing purpose, also the button is only writing the single parameter to a lone table with a lone column.

thanks again.|||ok, got tired of fighting with it so went around it...


Dim connString As String
connString = "............."
Dim myConnection As New SqlConnection(connString)
Dim myCommand As New SqlCommand("test1", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

Dim strTempString As String
Dim lstTempListbox As New ListBox
Dim arrTemparray As New ArrayList
Dim x As Integer

lstTempListbox.DataSource = Session("lstDates")
lstTempListbox.DataBind()

For x = 0 To lstTempListbox.Items.Count - 1
If strTempString = "" Then
strTempString = lstTempListbox.Items(x).ToString
Else
strTempString = strTempString + lstTempListbox.Items(x).ToString
End If
Next

Dim parameterDates As New SqlParameter("@.Dates", SqlDbType.VarChar, 4000)
parameterDates.Value = strTempString
myCommand.Parameters.Add(parameterDates)

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

the table gets the data nicely formatted into a single cell and i can spit it back out in the RTF without formatting issues.

hope it helps someone else :)
andy

Monday, March 19, 2012

List the folder contents using SQL

Hi all,
I have built a Disaster Recovery Site for my DB.on periodic basis, trn files from production server reach DR server and DR setup will apply them locally.

If the flow is smooth then no issues, if one of the file does not reach DR
the entire setup will halt for the want of the file and I dn't have any means to
know which file is missing.

Both my production and DR site located remotely behind firewalls, i.e i can't
physically access the servers or remotely login to the server.

Can anyone tell me how to see the contents in a folder in the server using
SQL query .

Any help is highly appreciated

Thanks and Regards
Srinivas VaranasiI'd use xp_cmdshell (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp).

-PatP|||use

master..xp_cmdshell 'dir c:\'|||Thanks Pat.|||Harshal, sorry to find "STUPID" as Ur Signature

Wednesday, March 7, 2012

List of Backups is too big

I have a Maintenance Plan which runs Backup of DB every hour. Backups older
than 2 weeks are deleted automatically. If I check the contents of the
folder containing Backup files then I do not see there those old files which
had to be deleted. They were really deleted. But if I select Restore
Database in EM then I get the list of all files, including deleted ones.
I noticed that the list of Backup files is delivered with bigger and bigger
delay. Maybe I'm wrong but I think it's because of the size of that list.
I'm working with remote Database through VPN connection and I would like to
find the way to make the list of Backup files contain only existing files.
Thank you
Al
That is because each time you backup using the SQL Server Backup command(or
thru the wizard) a row is added to the backup history tables. These rows
are never deleted automatically. You must set up a job or manually run
sp_delete_backuphistory on a regular basis to cap the number of rows in the
history tables. Be aware that the first time you run it the response will
be slow if there are lots of rows in the tables. Once you get it down to a
reasonable size it works just fine.
Andrew J. Kelly SQL MVP
"vul" <aaa@.optonline.net> wrote in message
news:u2m0hnh1EHA.3588@.TK2MSFTNGP14.phx.gbl...
>I have a Maintenance Plan which runs Backup of DB every hour. Backups older
> than 2 weeks are deleted automatically. If I check the contents of the
> folder containing Backup files then I do not see there those old files
> which
> had to be deleted. They were really deleted. But if I select Restore
> Database in EM then I get the list of all files, including deleted ones.
> I noticed that the list of Backup files is delivered with bigger and
> bigger
> delay. Maybe I'm wrong but I think it's because of the size of that list.
> I'm working with remote Database through VPN connection and I would like
> to
> find the way to make the list of Backup files contain only existing files.
> Thank you
> Al
>
|||Thank you very much, Andrew
Al
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:#JxGC9h1EHA.1860@.TK2MSFTNGP15.phx.gbl...
> That is because each time you backup using the SQL Server Backup
command(or
> thru the wizard) a row is added to the backup history tables. These rows
> are never deleted automatically. You must set up a job or manually run
> sp_delete_backuphistory on a regular basis to cap the number of rows in
the
> history tables. Be aware that the first time you run it the response will
> be slow if there are lots of rows in the tables. Once you get it down to
a[vbcol=seagreen]
> reasonable size it works just fine.
>
> --
> Andrew J. Kelly SQL MVP
>
> "vul" <aaa@.optonline.net> wrote in message
> news:u2m0hnh1EHA.3588@.TK2MSFTNGP14.phx.gbl...
older[vbcol=seagreen]
list.[vbcol=seagreen]
files.
>