Table access query - sql-server-2005

In our server client software in vb6 with SQL2005, On server side one SQL table is continuously updated by data and we need to display data from this same table on client at running time. Pleases help how to access this same table from server and client so that data is continuously updated from server side and records in this table show on client software without error.

Your VB application needs to poll the table on occasion (as often as you need it to) to gather the new data, then display it as needed. Further assistance is going to require more information from you (such as, are you just asking us to write this for you?).

In VB6 you can use a timer control on the form to periodically check and reload the data to the form. If you are using an ADO recordset then reload the recordset with the table data and rebind to your form's values OR if you are using the built-in binding you will have to tell the form to reload and/or rebind. It's been a while since I have done VB6 so my memory on the exact steps is a little rusty.

Related

Running/Printing a report from VB6 application using ACCESS with data loaded from Sql

I have a simple VB6 application where I input information and store it on SQL SERVER. I went ahead and linked Access 2007 and SQL Server so that all my tables are in Access for report generating purposes. I created a mock report, and was able to generate a report for all users from the sql Table (from Visual basic) Now my question is this, on the report form in the VB application, I have a combobox that's being populated with Client Names from the sql server. What I need to do is allow the user to choose a name from the combobox and click PRINT and allow them to only generate the report for that one user. The names in the combobox have ID's assigned to them. I'm having a hard time coming up with a way to edit the query in access (where id=17) from VB to allow the report to be only generated for one user. Thanks for any and all help!
Dont you think that sending a query from VB6 to Access would be a better way instead of modifying the queries in Access.
Hope I understood your question correctly.

Race condition caused by cursors persisted to temp files - is it possible

I'm troubleshooting a problem with a Visual Fox Pro application (built with the Visual Fox Express framework) which I suspect is being caused by a race condition. The application is being hosted on a Citrix XenApp server and under certain conditions, data displayed on a certain form appears to be incorrect, and changes to something other than what the user is entering.
The form in question displays a list of records returned from a query on a SQL Server database based on certain information entered by the user.
If this is what is happening I suspect the sequence of events is something like this:
1) User 1 enters data and causes form to dispay grid of data of
results returned from database.
2) User 2 opens same form on different Citrix session and enters data
causing form to display a grid data of results returned from database.
This cursor gets persisted to disk and overwrites, or somehow
conflicts with User 1's cursor for that form.
3) Some FoxPro cursor mechanism on User 1's instance sees changed data
in the cursor (from User 2) and updates the screen with data from the
cursor.
I don't know much about how FoxPro works but from what I understand in some circumstances a cursor will be persisted to a temp file. On our Citrix application server this temp folder may be shared by between 10 and 50 users. I'm looking for information about if a race condition caused by a cursor written to a file in the temp folder is something that is even possible so that I can continue researching down that path or rule it out definitively.
I know there are ways to make it so that the FoxPro temp files are written to a different folder for each user and I am working on making the change to do that but I would like to find out if anyone else has seen a similar problem or thinks that what I suspect is actually possible.
IT does sound strange, but yes, Foxpro creates temp tables of cursors it uses for display and query results, such as local or remote data access. However, when created, they are created as read-only or read-write, but ONLY for the person per connection. When a cursor attempts to be created, it generates a random file name for the results and uses that as the .dbf cursor for presenting to the user.
COULD IT be a racing issue? I doubt that, but not knowing specifics of the quite old Visual FoxExpress framework, don't know what/where you would configure to have it dynamically use a different location of temp files. It should be going to the temp files path of the Windows environment variables. So, if users of the Citrix connection are using the same user / password for multiple sessions, yes, it would go to the same location, but when trying to generate the temp file, it would fail getting an exclusive handle and try again with the next random file name.
I'd say very unlikely that temp files are implicated here. Each cursor you create uses a different temp file; I don't see how two users, even in a Citrix-type situation, would share a single temp file.

Create Access databases programatically through vb.net

Let me preface this by saying that I know this is a stupid way to go about this, but it needs to be handled in this way.
I need to make an application that from a master database creates a number of access database files (tables of a larger db), then these are manually given to users who fill in data, the database files are emailed back to a user who, through the application, combines them again.
The only part of this that I am unsure about is problematically creating the access db's. I have read that through Microsoft Jet OLE DB Provider and Microsoft ADO Ext I can create them (the tables and data), but I also need forms.
I have yet to start writing anything and this is away from my area of work, so any insight/links would be much appreciated.
Also, I would hope to be able to write this in the free express version of visual studio. Are there components needed that would prevent me from this? Thanks.
If you are developing in vb.net then why do you need forms in the Access database? Create a vb.net application for the "client" pcs with the required forms reading and writing to the Access database.
If however you do need to have forms in an Access database. Create a database with the required forms and code. Distribute the code/form database and the data database. Add a method to the code/form database the creates links to the tables in the "data" database.

WPF Data Bound Control, Detect SQL Table change

I'm having a moment of stupidness.
I have a Treeview control in WPF, that is displaying a list of Quotes, ie Quote#, Quote Name eg "Q#1000" "Server Quote" This treeview is bound to a collection of objects
public ObservableCollection quoteitems = new ObservableCollection();
Which are loaded from a SQL database via an SQLDataReader which populates the collection. Changes to the Quotes Collection are committed to SQL after calling a QuoteUpdate() method that writes the changes to the collection back to the database.
The problem is, what happens if a another user using the same app changes the Name of a Quote. How can I detect a change to the table, WITHOUT polling the table for updates, or using a timmer to refresh the data in the TreeView?
Am I missing something in binding controls to SQL? Is there a way to bind a control to a table and have updates handled by the control automatically? I see "two way data binding" and that seems to be what I'm after but haven't seen a way to do this with an SQL data source. Or am I having a dumb moment with how I'm thinking about the way SQL actually works!
If you're using SQL Server (version 2005 and above), you can use Query Notifications to monitor changes. Have a look at this article to get a headstart on this.

Building an auditing system; MS Access frontend on SQL Server backend

So basically I'm building an app for my company and it NEEDS to be built using MS Access and it needs to be built on SQL Server.
I've drawn up most of the plans but am having a hard time figuring out a way to handle the auditing system.
Since it is being used internally only and you won't even be able to touch the db from outside the building we are not using a login system as the program will only be used once a user has already logged in to our internal network via Active Directory. Knowing this, we're using a system to detect automatically the name of the Active Directory user and with their permissions in one of the DB tables, deciding what they can or cannot do.
So the actual audit table will have 3 columns (this design may change but for this question it doesn't matter); who (Active Directory User), when (time of addition/deletion/edit), what (what was changed)
My question is how should I be handling this. Ideally I know I should be using a trigger so that it is impossible for the database to be updated without an audit being logged, however I don't know how I could grab the Active Directory User that way. An alternate would be to code it directly into the Access source so that whenever something changes I run an INSERT statement. Obviously that is flawed because if something happens to Access or the database is touched by something else then it will not log the audit.
Any advice, examples or articles that may help me would be greatly appreciated!
Does this work for you?
select user_name(),suser_sname()
Doh! I forgot to escape my code.
Ok, it's working here. I'm seeing my windows credentials when I update my tables. So, I bet we missed a step. Let me put together a 1,2,3 sequence of what I did and maybe we can track down where this is breaking for you.
Create a new MSAccess database (empty)
Click on the tables section
Select external data
Pick ODBC database
Pick Link to the datasource by creating a linked table
Select Machine datasource
Pick New...
System Datasource
Pick SQL Server from the list and click Next, Finish.
Give the new datasource a name and description, and select (local) for the server. Click Next.
Pick "With Windows NT authentication using the network login ID". Click Next.
Check Change the default database to, and pick the DB. Click Next. Click Finish.
Test the datasource.
Pick the table that the Trigger is associated with and click OK.
Open the table in Access and modify one of the entries (the trigger doesn't fire on Insert, just Update)
Select * from your audit table
If you specify SSPI in your connection string to Sql, I think your Windows credentials are provided.
I tried playing with Access a bit to see if I could find a way for you. I think you can specify a new datasource to your SQL table, and select Windows NT Authentication as your connection type.
Sure :)
There should be a section in Access called "External Data" (I'm running a new version of Access, so the menu choice might be different).
Form this there should be an option to specify an ODBC connection.
I get an option to Link to the datasource by creating a linked table.
I then created a Machine datasource. I selected SqlServer from the drop down list. Then when I click Next, I'm prompted for how I want to authenticate.
CREATE TRIGGER testtrigger1
ON testdatatable
AFTER update
AS
BEGIN
INSERT INTO testtable (datecol,usercol1,usercol2) VALUES (getdate(),user_name(),suser_sname());
END
GO
We also have a database system that is used exclusively within the organisation and use Window NT logins. This function returns the current users login name:
CREATE FUNCTION dbo.UserName() RETURNS varchar(50)
AS
BEGIN
RETURN (SELECT nt_username FROM master.dbo.sysprocesses WHERE spid = ##SPID)
END
You can use this function in your triggers.
It should be
select user name(),suser sname()
replace spaces with underscores
you need to connect with integrated security aka trusted connection see (http://www.connectionstrings.com/?carrier=sqlserver)
How many users of the app will there be? Is there possibility of using windows integrated authentication for SQL authentication?
Updated: If you can give each user a SQL login (windows integrated) then you can pickup the logged on user using the SYSTEM_USER function.
My solution would be not to let Access modify the data with linked tables.
I would only create the UI in Access and create an ADO connection to the server using windows authenticated in the connection string. Compile you Access application as dbe to protect the VB code.
I would not issue SQL statement, but I would call stored procedures to perform the changes in the database, and create the audit log entry in an atomic transaction.
The UI (Access) does not need to know the inner works on the server. All it needs to do is request and update/insert/delete using the stored procedures you would create for this purpose. The server should handle the work.
Retrieve a record set with ADO using a view with the hint NOLOCK implemented in the server and cache this data in Access for local display. Or retrieve a single record and lock only that row for editing.
Using linked tables your users will be locking each other.
With ADO connections you will not have the trouble to set ODBCs on every single client.
Create a table to set the server status. You application will check it before any action. you can use it to close the server to the application in case that you need to perform changes or maintenance.
Access is a great tool. But it should only handle its local data and not be allowed to mess with the precious server.