View Single Post
  #1 (permalink)  
Old June 24th, 2009, 05:00 AM
RobCarter RobCarter is offline
Authorized User
 
Join Date: Nov 2005
Location: Bromsgrove, United Kingdom.
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Unhappy Starting a console App from a vb.net windows app

Hi

I am a kinda VB.net noob so I am after as much constructive advice as possible for my issue:

I have a console app that was built by a contractor who has now left our company. It needs to be run every 7th working day.

Obviously, once the console app has finished its task it shuts down so I need a persistent application to begin the task again.

(it is at this point I would envisage people mentioning windows services but at this moment in time the mechanics of that is beyond my limited scope)

I have built a timer that looks at 7th working day and I now need for that windows app to open my console app. The exe opens but then I get a security permissions exception.

The code that invokes the console app is:

Code:
Imports LE22ExtractManager.clsDates
Imports System.Data.sqlclient
Imports System.Data.Sql
Imports System.Data
Imports Microsoft.VisualBasic.DateAndTime
Imports System.Diagnostics.Process
Namespace Medefeed
PublicClass clsMedeFeed
PublicSharedSub Check7thDay(ByRef MedeSwitch AsInteger)
Dim myFYst AsInteger = FiscalYearStartMonth.Apr
Dim dtpEnd AsString = Format(DateAdd(DateInterval.Day, -1, Today), "yyyyMMdd")
Dim dtpStart AsString = fiscalYear(myFYst, Today) & Right("00" & myFYst, 2) & "01"
Dim dDate AsString = Right("000" & Day(Today).ToString, 2) & "/" & Right("000" & Month(Today()).ToString, 2) & "/" & Year(Today()).ToString
Dim tot_rec AsInteger
Dim strConnection AsString = "Server=myserver;Database=Mydb;User ID=user;Password=pwd;Trusted_Connection=False;"
Dim sConn AsNew SqlConnection(strConnection)
Try
Dim sqlCommand AsNew SqlCommand("POPULATE_TIME_DIMENSION", sConn)
With sqlCommand
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@dtstartdate", dtpStart)
.Parameters.AddWithValue("@dtenddate", dtpEnd)
EndWith
sConn.Open()
 
sqlCommand.ExecuteNonQuery()
Catch ex As Exception
Finally
sConn.Close()
EndTry
Dim sSql AsString = "select * from dim_time where "
sSql += "fulldatealternatekey = '" & dDate & "' and "
sSql += "numworkdays = 7"
Dim myDA As SqlDataAdapter = New SqlDataAdapter(sSql, sConn)
Dim myDs AsNew DataSet
Try
feedback("Started Building Medefeed")
sConn.Open()
myDA.Fill(myDs, "DateFinder")
tot_rec = myDs.Tables(0).Rows.Count
If tot_rec = 0 Then
Process.Start("\\server\f$\dir\dir\PatientCosting.exe")
MedeSwitch = 0
Else
MedeSwitch = 1
EndIf
'End If
Catch ex As Exception
Finally
myDA = Nothing
myDs = Nothing
sConn.Close()
EndTry
The exception that I get displays: System.Security.Permissions.SecurityPermission

If more information is needed I would be happy to clarify further.

Thanks for any help anyone can provide - I am totally stuck with this.

Rob
__________________
Rob Carter