|
How about implementing a timer control on the main form which checks the connection to the database periodically ? You could even implement a stoplight (red / green) and design limited functionality into your application where some transactions could be stored locally (xml ?) until the database connection has been resumed.
In an ideal world, you would have built a data access layer where you can centralize your access to the database, implement try-catch blocks, logging, administrative notifications, etc.
Good luck and tell us which way you decided to go.
|
|
|
|
|
Thanks to all....
I've got a timer which runs every second to update a clock so I could put it there, or I could put try/catch around all the datareaders as it's not a huge app.
However, I'm going to have a look into building a data access layer into the application. I'm still fairly new to programming and it's something I'll have to teach myself eventually anyway so I might as well start now whilst the data access in this app is fairly limited!
Thanks again,
Chris
|
|
|
|
|
ok, so let me ask if I'm getting this right! I've added a class to act as the DAL:
Public Class data
Public Function opendatabase(ByVal solid As Odbc.OdbcConnection, ByVal dsn As String)
Try
solid.ConnectionString = "dsn=" & dsn & ";uid=xxxx;pwd=xxxx"
solid.Open()
desktop.connectionstring = "dsn=" & dsn & ";uid=xxxx;pwd=xxxx"
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function readdata(ByVal solid As Odbc.OdbcConnection, ByVal sqlquery As String, ByRef datareader As Odbc.OdbcDataReader)
Try
Dim command As New Odbc.OdbcCommand(sqlquery, solid)
datareader = command.ExecuteReader
Return True
Catch ex As Exception
Return False
End Try
datareader.Close()
End Function
Public Function storedata(ByVal solid As Odbc.OdbcConnection, ByVal sqlcommand As String)
Try
Dim command = New Odbc.OdbcCommand(sqlcommand, solid)
command.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
So whenever I need to read/write/open the database I call these functions. I now just need to put the error messages asking them whether they want to try to re-connect etc where these three functions are returning false.
I'm guessing adding a business logic layer would be to process these results (from the data reader anyway) in a seperate class to the UI and passing it only the detail it needs to affect the UI?
btw this helped explain the tiers quite well.
Chris
|
|
|
|
|
|
If you want to check connectivity due to network failure there is a event in the application events called NetworkAvailabilityChanged (the e parameter has a property IsNetworkAvailable )
You can use that one but this does not catch the event where your database server is down but network is still working.
So you will still need to implement some sort of polling the database to see if it is still up.
|
|
|
|
|
Are you using a single connection to the database that's continuously open? If so, why?
I are Troll
|
|
|
|
|
Yes, there is a single connection that is always open. I'm not doing it this way for one particular reason apart from it's easier to manage I guess. Also, the application itself manages a series of other Uniface apps, which makes up 98% of the software, which each have a constantly open connection to the database....
|
|
|
|
|
That's a really bad practice. SQL connection licenses are usually pretty expensive. The accepted normal practice is to open your connection, execute your query, and close the connection - for each db operation.
|
|
|
|
|
well we've got no choice with Uniface....well, i guess we could close and open connections for the thousands of clear and retrieves the system uses but It would be considered bad practise in the Uniface environment. Our database licenses restricts us to 5 connection per user which is enough (we did have unlimited connections for a long time!) so cost isn't a factor. I'm sure if we were to change from the Solid database we use we may need to change things
|
|
|
|
|
Not to sidetrack this thread, but I hadn't heard this argument before.
When you say "expensive", are you referring to the financial cost of the licenses, or in terms of performance? We run off Oracle databases here, that are licensed per-CPU instead of per-connection, and my software works entirely with persistent connections (A login takes a couple seconds).
|
|
|
|
|
Licenses can either be per-CPU or per-Seat and they cost a small fortune per.
|
|
|
|
|
I've been working on a script that will collect information from the computers on our network.
First I generated a list of computer names by getting the information from Active Directory and put it into a text file
Second I've got a script that will go through the list of computer names and gather the information and put it into a .csv file.
So far everything is working just fine except for when I need to read information from the registry.
I get all the correct information for the WMI stuff for each computer but for the registry information, what I get is the information from the computer running the script rather than the remote computer.
What I need help with is modifying the code so I can access the registry on the remote computers.
Next
' Now get all the Monitor Info
objOutputFile.Write ", ," & GetMonitorInfo() & vbNewLine
Else
'WScript.Echo strComputer & " not found..."
objOutputFile.Write "*** " & strComputer & " *** NOT Found" & vbCrLf
Err.Clear
End If
Next
End If
End If
End Sub
'DISPLAY_REGKEY sets the regkey where displays are found. Don't change except for debugging
'I only change it when I am looking at a .REG file that someone sent me saying that the
'code doesn't work.
Const DISPLAY_REGKEY="HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\"
'sets the debug outfile (use format like c:\debug.txt)
Const DEBUGFILE="NUL"
'if set to 1 then output debug info to DEBUGFILE (also writes debug to screen if running under cscript.exe)
Const DEBUGMODE=0
'The ForceCscript subroutine forces execution under CSCRIPT.EXE/Prevents execution
'under WSCRIPT.EXE -- useful when debugging
'ForceCScript
DebugOut "Execution Started " & cstr(now)
'wscript.echo GetMonitorInfo() 'just write the output to screen
DebugOut "Execution Completed " & cstr(now)
'This is the main function. It calls everything else
'in the correct order.
Function GetMonitorInfo()
debugout "Getting all display devices"
arrAllDisplays=GetAllDisplayDevicesInReg()
debugout "Filtering display devices to monitors"
arrAllMonitors=GetAllMonitorsFromAllDisplays(arrAllDisplays)
debugout "Filtering monitors to active monitors"
arrActiveMonitors=GetActiveMonitorsFromAllMonitors(arrAllMonitors)
if ubound(arrActiveMonitors)=0 and arrActiveMonitors(0)="{ERROR}" Then
debugout "No active monitors found"
strFormattedMonitorInfo="[Monitor_1]" & vbcrlf & "Monitor=Not Found" & vbcrlf & vbcrlf
else
debugout "Found active monitors"
debugout "Retrieving EDID for all active monitors"
arrActiveEDID=GetEDIDFromActiveMonitors(arrActiveMonitors)
debugout "Parsing EDID/Windows data"
arrParsedMonitorInfo=GetParsedMonitorInfo(arrActiveEDID,arrActiveMonitors)
debugout "Formatting parsed data"
strFormattedMonitorInfo=GetFormattedMonitorInfo(arrParsedMonitorInfo)
end If
Here is a link to the full code:
http://pastebin.com/n3JRYdUP[^]
|
|
|
|
|
The the relevant code here. Noone is going to download the entire project and look at it, especially from a "tiny" URL.
|
|
|
|
|
That would require the appropriate rights for both WMI and registry-access. I think that you might be missing the last one.
I are Troll
|
|
|
|
|
Hi, I am need to something similar to this for 2000 machines in my office in Dublin Ireland, Did you get around the permission or access issue for the Registry information for the Monitor information? I would very much like to know how you achieved this. I am not a coder more of an analyst, I have a VB script that grabs all the info via I need via WMI the only part I am missing is the monitor information.
Kind Regards,
Damien.
|
|
|
|
|
How to broadcast data over LAN network using UDP protocol through the winsock control in VB6.0.
I found connect() method as-
winsockClient.connect(0,5050)
where 0 is indicating broadcasting and 5050 is local port no.
But it is not working.
Is there any way to broadcast data using UDP protocol.
Thanks in adv......
modified on Monday, September 20, 2010 9:43 AM
|
|
|
|
|
|
Thanks for ur reply and suggestion. But I have so limitation thats why I have to work on tje VB6.Now come on the topic..
The link U have given has very good example.But I have to broadcast the data over LAN network.
So which remotehost I have to use or is there any method to broadcast over network?
Thanks in adv..
|
|
|
|
|
What?
The RemoteHost IP Address is the endpoint of the communication, it doesn't matter if it is an internal or external IP. the traffic will be routed round the internal network until it reaches the gateway with the external bridge and then continue to its destination on the external network.
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
Suppose I use Rmote host as "127.0.9.8" which is in network.But whgn I send the data over the network then system connected in the network do'nt find it and do'nt respond it.
and When I use Remote host as "255.255.255.255" then all the systems detect the data as "255.255.255.255" is the broadcast address.
That was the question I was finding.
|
|
|
|
|
See this, (there are bound to be other definitions on the net if you go looking;
BroadCast Adddress[^]
Basically, 255.255.255.255 is a broadcast address and will only broadcast to end points within the same network subnet/segment.
And a little refresher on UDP[^]
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
Hi,
I wrote a program that print mutiple pages. al with different information ofcourse.
Can I with 1 printdocument split it into multiple tasks into the printer.
If yes point me to the write direction please
Also Is there a way to "see" of the printroutine prints to a printpreview or realy to the printer?
Jan
|
|
|
|
|
Is this VB6?
A print document, is exactly that, a single 'job' with multiple pages as required. I do not see how or why you would want to split this into multiple tasks.
If you do, you would want to create printdocuments for each task e.g. for routing to different printers with different letterheads etc.
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
It's not VB6, it's vb.net2010 (no printpreview in vb6)
I want to split it becaurse several 100 pages at ones is a long time to wait for some collegaes. ( we need to login into the printer and the jobs wait ontil we do) So if I split it into 8 times 100 instead of 800 al at ones I can wait and let someone pass trhu
So on this problem I need to rewrite some code
Jan
|
|
|
|
|
Split your data into 8 groups and pass them to the report one at a time... eg: Records 1 to 100, then 101 to 200 etc...
|
|
|
|