VB6 Memory leak from Interop object - vb6

I have an activeX interop control that is used in an old VB6 application. The ActiveX control is a gridview component and it loads a few hundred thousand records, eating up approx 300MB of Memory every time its started.
Eventually VB runs out of memory.
The interop control is referenced like a normal activex control and loaded using the following code
dim withevents gridview as vbcontrolextender
dim withevents uv as applicationlistcontrol.appgrid
dim imc as applicationlistcontrol.iappgrid
private sub form_load
set gridview = Controls.Add("Applicationlistcontrol.appgrid", "ApplicationListView", me)
set uv = gridview.Control
set imc = uv
imc.FillGrid '(Calls the C# control and loads data into grid)
end sub
private sub form_unload
set imc = nothing
set uv = nothing
set gridview = nothing
end sub
The memory is also kept when exiting the application and returning to VB6 IDE and next time its started, another 300 MB get chewed up.
This is the function that loads the data:
using (SqlConnection connection = new SqlConnection(_connectionString))
{
connection.Open();
using (var command = new SqlCommand("SELECT * FROM APPLICATION_LIST WHERE APPLICATION_TYPE_ID = 1", connection))
{
using (var table = new DataTable())
{
table.Load(command.ExecuteReader());
}
}
}
GC.Collect();
GC.WaitForFullGCComplete();
return null;

Related

EWS: Add userproperties to an EML when saving it?

In some of my mails, I have stored some userproperties via Outlook...
item.UserProperties.Add("CustID", Outlook.OlUserPropertyType.olText)
item.UserProperties("CustID").Value = custID.ToString
On a Pc (server) without Outlook installed, I want to download mail as EML and store the userproperties (like 'CustID' etc.).
My code for saving the EML:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim service As New ExchangeService(ExchangeVersion.Exchange2013)
service.Credentials = New WebCredentials("my#email.com", "mypsw")
service.Url = New System.Uri("https://outlook.office365.com/EWS/Exchange.asmx")
Dim entryID As String = "00000000C802F40668D27342B788D508E9210A67005DF9A7DEF7194A418C8515031D4262280000E00005DF9A7DEF7194A418C8515031D4262280002A9D18B320000"
Dim id As New ItemId(Convert(service, "my#email.com", entryID))
Dim email As EmailMessage = EmailMessage.Bind(service, id)
Dim ps As PropertySet = New PropertySet(ItemSchema.MimeContent)
email.Load(ps)
Using fileStream = New IO.FileStream("D:\sandbox\_email_test.eml", IO.FileMode.Create)
fileStream.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length)
End Using
End Sub
Private Function Convert(service As ExchangeService, mailbox As String, entryID As String) As String
Dim originalID As New AlternateId()
originalID.Format = IdFormat.HexEntryId
originalID.Mailbox = mailbox
originalID.UniqueId = entryID 'EntryId retrieved from email in Outlook
Dim altBase As AlternateIdBase = service.ConvertId(originalID, IdFormat.EwsId)
Dim convertedID As AlternateId = DirectCast(altBase, AlternateId)
Dim strConvertedID As String = convertedID.UniqueId
Return strConvertedID
End Function
Is there a way I can store userproperties in an EML? If yes, if I double click the EML to open it in Outlook, can I read back the userproperties from the EML?
Thanks!
User Properties are Mapi/Extended properties which aren't include in the MimeStream of a Message. If you add the properties as X-headers instead then they would be available in the MimeSteam otherwise you would better to export the Message as a MSG file which will give you full fidelity on all MAPI properties. To export as a MSG you will need to use Outlook and maybe look at something like redemption http://www.dimastr.com/redemption/rdo_introduction.htm if you need automation.
Cheers
Glen

WP7 - Adding Settings page. Reading values from a different page?

So I've created a page called "Settings". Obviously in this page is where the settings are for the app. In the Settings page I've added 2 ToggleSwitches and 1 Listpicker. Using the Nokia Developer website on basics of Saving and reading Settings i managed to pull it off so it saves the states of the toggleswitches and listpicker.
The problem i'm having right now is that i need a way to read these saved setting values on the first page when the app starts so it can prepare the app accordingly. Soo far this is what i have in the Settings page:
Imports System.IO.IsolatedStorage
Partial Public Class Settings
Inherits PhoneApplicationPage
Private AppSettings As IsolatedStorageSettings
Public Sub New()
InitializeComponent()
AppSettings = IsolatedStorageSettings.ApplicationSettings
ListPicker1.Items.Add("Saved Notes")
ListPicker1.Items.Add("Important")
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
Try
Tg1.IsChecked = CBool(AppSettings("UseAccentColor"))
Tg2.IsChecked = CBool(AppSettings("GoBack"))
ListPicker1.SelectedIndex = CByte(AppSettings("StartListFalse"))
Catch ex As KeyNotFoundException
AppSettings.Add("UseAccentColor", False)
AppSettings.Add("GoBack", False)
AppSettings.Add("StartListFalse", False)
AppSettings.Save()
End Try
End Sub
Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
System.Diagnostics.Debug.WriteLine("Exiting, so save now")
AppSettings("UseAccentColor") = Tg1.IsChecked
AppSettings("GoBack") = Tg2.IsChecked
AppSettings("StartListFalse") = ListPicker1.SelectedIndex
AppSettings.Save()
End Sub
End Class
So soo far it saves on exit but i need a way to load these from startup i.e. my MainPage. Like a way to refer to this page and according to these settings change whatever needs to be changed.
How can i do this?
Thanks!
You managed to save Settings to IsolatedStorage, and IsolatedStorage is accesssible from any page of your application. So in MainPage, just read those setting from IsolatedStorage instead of the Settings Page.
EDIT :
You can do it just like in OnNavigatedTo method in Settings Page
Private AppSettings As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
'Tg1.IsChecked is analog with useAccentColor
Dim useAccentColor As Boolean = CBool(AppSettings("UseAccentColor"))
'Tg2.IsChecked = goBack
Dim goBack As Boolean = CBool(AppSettings("GoBack"))
'ListPicker1.SelectedIndex = startListFalse
Dim startListFalse As Byte = CByte(AppSettings("StartListFalse"))

Rich Text in a VB6 text box

Does anyone know if there is a way outside of using a 3rd Party text box control, to enter HTML into a VB6 text box.
I havent found anything online.
Hopefully you'll be able to make use of this. We're doing it in .Net to allow a simple edit control on forms to send formatted emails. As such we have a RTF text box with a custom menu for creating the text, then we extract the RTF, convert it to HTML and add it as HTML content as the body of an email. The RTF to HTML conversion uses the code from this article: http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter
Here's the wrapper code we use to tie this together - it simply takes an RTF input and directly returns an HTML output:
Imports Itenso.Rtf
Imports Itenso.Rtf.Support
Imports Itenso.Rtf.Parser
Imports Itenso.Rtf.Interpreter
Imports Itenso.Rtf.Converter.Image
Imports Itenso.Rtf.Converter.Html
Imports Itenso.Sys.Application
Namespace Email
Public Class RtfToHtml
Public Function Convert(inText As String) As String
Dim struct = ParseRtf(inText)
Dim doc = InterpretRtf(struct)
Return ConvertHtml(doc)
End Function
Private Function ParseRtf(inText As String) As IRtfGroup
Dim structureBuilder As New RtfParserListenerStructureBuilder
Dim parser = New RtfParser(structureBuilder) With {.IgnoreContentAfterRootGroup = True}
Dim source = New RtfSource(inText)
parser.Parse(source)
Return structureBuilder.StructureRoot
End Function
Private Function InterpretRtf(rtfStructure As IRtfGroup) As IRtfDocument
Dim settings = New RtfInterpreterSettings With {.IgnoreDuplicatedFonts = True, .IgnoreUnknownFonts = True}
Return RtfInterpreterTool.BuildDoc(rtfStructure, settings)
End Function
Private Function ConvertHtml(document As IRtfDocument) As String
Dim settings As New RtfHtmlConvertSettings With {.Title = "Notification Of Shipment",
.IsShowHiddenText = False,
.UseNonBreakingSpaces = True}
Dim converter = New RtfHtmlConverter(document, settings)
'converter.StyleConverter = New RtfEmptyHtmlStyleConverter
Return converter.Convert
End Function
End Class
End Namespace
Depending on your application you could simply wrap this up in an assembly and call it from VB6. We've done this in the past and it's reasonably straightforward. Again, more info if you think it might be useful to you

Dynamically added Raddocks Optimization?

We have a optimization problem regarding rad dock controls. The requirement of project is such that we are creating dynamic raddocks on the fly and adding it to a raddockzone, then we are saving the raddock "type" etc in a mssql db. We also have a collector window/raddockzone in which we have build a functionality where we can drag a dock and save it in collector. As with the first raddockzone we are adding the dock in collector on the fly. Now while adding a dock or moving it to another raddockzones it takes sometime. Our client is comparing it with the example of the demo link : http://demos.telerik.com/aspnet-ajax/dock/examples/content/defaultcs.aspx
Following is our code snippet to add dock on the fly:
private RadDockNew CreateRadDock()
{
//string[] allowedZones = { "RDZCollector", "RadDockZone2" };
int width = Convert.ToInt32((hdnWidth.Value == "") ? "520" : hdnWidth.Value);
RadDockNew dock = new RadDockNew();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
dock.ID = string.Format("RadDock{0}", dock.UniqueName);
//dock.Title = dock.UniqueName.Substring(dock.UniqueName.Length - 3);
dock.Width = Unit.Pixel(width);
dock.CssClass = "RadDockZoneMain";
//dock.AllowedZones = allowedZones;
dock.Style.Add("min-height", "290px");
dock.OnClientDockPositionChanged = "DropInCollector";
//dock.EnableViewState = false;
DockCommand cmd = new DockCommand();
cmd.Name = "Setting";
cmd.Text = "Setting";
cmd.OnClientCommand = "showSettings";
dock.Commands.Add(cmd);
DockCommand dc = new DockCommand();
dc.Text = "Trash";
dc.Name = "Trash";
dc.OnClientCommand = "CloseDock";
dc.CssClass = "rdClose";
dc.AutoPostBack = true;
dock.Commands.Add(dc);
DockToggleCommand cmd2 = new DockToggleCommand();
cmd2.CssClass = "rdCollapse";
cmd2.AlternateCssClass = "rdexpand";
cmd2.OnClientCommand = "ChangeImage";
//DockCommand collapse = new DockCommand();
//collapse.Text = "Collapse/Expand";
//collapse.Name = "Collapse/Expand";
//collapse.OnClientCommand = "CollapseDock";
//collapse.CssClass = "rdCollapse";
dock.Commands.Add(cmd2);
return dock;
}
Please tell if there is any way to optimize / make it faster.
Thanks.
I examined the attached code sample and I think that it is correct. My suggestions are to check if the problem persists if you use other storage medium, instead of a database or if there are client script errors on the page, containing the RadDocks.
As the setup of your project seems to be similar to the one, implemented in the My Portal demo, I would recommend using the example in the Code Library article Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel as a reference.

No valid report source is available. in asp.net sap crystal report

I am using Sap Crystal Report in asp.net 2010
It will shows the error no valid report source id available, when i refreshing the report or moving to next page at run time using report viewer tools
and this is my coding,
Dim crdoc5 As New ReportDocument()
Dim crtablogoninfo5 As New TableLogOnInfo
Dim crtabs5 As Tables
If Not IsPostBack Then
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Session.Add("CrStaffrecruit", crdoc5)
CrystalReportViewer5.ReportSource = crdoc5
Else
CrystalReportViewer5.ReportSource = Session("CrStaffrecruit")
End If
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Dim crconninfo5 As New ConnectionInfo()
rconninfo5.ServerName = "servername"
crconninfo5.DatabaseName = "databasename"
crconninfo5.UserID = "sa"
crconninfo5.Password = ""
crtabs5 = crdoc5.Database.Tables()
For Each crtab5 As CrystalDecisions.CrystalReports.Engine.Table In crtabs5
crtablogoninfo5 = crtab5.LogOnInfo
crtablogoninfo5.ConnectionInfo = crconninfo5
crtab5.ApplyLogOnInfo(crtablogoninfo5)
Next
CrystalReportViewer5.ReportSource = crdoc5
CrystalReportViewer5.RefreshReport()
If any one know pls help me...
Thanks in advance
For this please go through the following link
http://forums.sdn.sap.com/thread.jspa?messageID=10951477&#10951477
Although the following code is in C#, it shouldn't be too difficult to translate it to VB and it should solve your issue:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//whatever you do when the page is loaded for the first time
//this could even be bindReport();
}
else
{
bindReport();
}
}
public void bindReport()
{
ReportDocument rptDoc = new ReportDocument();
dsSample ds = new dsSample(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Crystal Report Example";
dt = getMostDialledNumbers(); //This function populates the DataTable
ds.Tables[0].Merge(dt, true, MissingSchemaAction.Ignore);
// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("yourReportFilePath.rpt"));
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
//in case you have an UpdatePanel in your page, it needs to be updated
UpdatePanel1.Update();
}
I was experiencing the same problem. In what event are you executing the code you posted? I ask because after much debugging, I discovered that you need to place the code in Page_Load (as opposed to PreRender like I was doing previously...)
Hope this helps.
I have got this problem several times, and the solution is to save the Report Document variable in a session then in the Page_load put the below code:
if (IsPostBack)
{
if (Session["reportDocument"] != null)
{
ReportDocument cr = new ReportDocument();
cr = (ReportDocument)Session["reportDocument"];
CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.DataBind();
}
}
NB:
Don't forget to fill the (Session["reportDocument"]) with the Display button.
Go through following link. I resolved same issue with that solution.
http://www.aspsnippets.com/Articles/ASPNet-Crystal-Reports-13-Visual-Studio-2010-CrystalReportViewer-Search-Button-Issue---No-valid-report-source-is-available.aspx

Resources