Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Best efficient desgin - MS Access FE and MS SQL BE

    Hi,

    i am trying to create the best design approach with MS Access as FE and MS SQL Server BE.

    I am wrting about here on MS SQL Server forum here:
    https://www.sqlservercentral.com/For...s-BE#bm1913427

    Post number #1913403.

    Code:
    Sorry, I was a little misleading when I said datagrid. What I meant is the data sheet view in an access form, I.e. you can bind a form, or certain objects (query for example) within a form to a local table via a sql statement. That table can either be in the frontend access file (controversial) or a separate access database file on the same drive as the FE (linked tables to FE). Either way, you can programmatically compact and repair at the end of the save routine, 
    The table is a user specific work space on the users local drive. In this scenario you can bind efficiently (I.e. there is no lag for the user editing and searching data (as it’s local) but to save you must check for changes and then write them back. I would, for smaller datasets, keep the last saved/original values in an array for comparison, on larger data sets i’d have an updatedBy audit field in the local table, you can bind a column/text box to a function, or give default values when the form opens, and use the audit fields not null to filter for updates in the save. 
    
    Also, you can buy third party data grids and embed them in forms, OCX, DLL etc, that are functionally much richer than the access data sheet view. There’s plenty to chose from.
    
    I’m not in front of a computer, using an IPad for this, so don’t have examples at hand. There’s plenty on google.
    Note that you should never create an application anywhere where you are passing dynamically created sql back to be executed by the server! All data access and manipulation should be via stored procedure and no user can access tables directly. Your approach would work but you are better off (mandatory) using stored procs as opposed to frontend sql statements.
    
    I wrote code once that would, based on a form template, create a fully disconnected access form with all code bespoke to the stored procedures that would handle the updates and reads. Basically build the template form with just the minimum objects etc. And then write a procedure, vba, to merge predefined vba, stored as data or a constant etc., with the detail from the table definition (which you should be able to read in a dev environment easily enough via ADO or DAO table or recordset definitions. In access you can easily create forms programmatically as well as set att the properties and set the forms code modules text. 
    
    My general approach:
    
    - for forms displaying only one record: use ado commands to both read and write.
    - for forms with only a few records returned I usually do the same as above, but on the read, the stored procedure returns a single delimited string containing the rows. Important: command objects are better than recordsets. Let the front end delimit the string. I also use this for populating short lists on combo boxes etc. On the save I would save row by row mimicking the default data sheet behaviour in access (I.e. data is updated when the user moves to another row etc.
    - for larger datasets, read a recordset into a local mdb table, use and audit field to mark updated records and then when saving i’d use and adodb command either once per row, or in batches where there are enough parameters to handle multiple rows, or with all data as a delimited string that can be passed into a table variable or something in t-sql for smaller datasets (e.g. person title, month, day of week etc.).
    
    In some cases you might want to able to allow the user to specify when to save, generally for larger datasets, so they can either work off line, or simply review all changes before committing. I’ve done a few systems where the user could “book out” data, work on it remotely and then book it back in at a later date.
    
    The vba would roughly contain:
    
    - form open/load procedure to call read procedure etc.
    - read procedure
    - form population procedure 
    - has changed function
    - validation function
    - save function
    - form exit function to check and warn about unsaved changes etc. 
    I want to ask you few questions which are more about Access then MS SQL Server.

    General approach building data model is use Access with no linking tables, only forms in Access and recordsouce from MS SQL Server using ADO/ADODB connections.

    I would, for smaller datasets, keep the last saved/original values in an array for comparison, on larger data sets i’d have an updatedBy audit field in the local table,
    What author wants to do it here with array comparison?
    Second option I understand because you can add dates when user inputting new data and you will have audit fields...


    Also, you can buy third party data grids and embed them in forms, OCX, DLL etc, that are functionally much richer than the access data sheet view. There’s plenty to chose from.
    Are you, Access Experts using something like this? Can you give any example?

    In access you can easily create forms programmatically as well asset att the properties andset the forms code modules text.
    Why to create new forms automatically?
    I can have one stable form and simple read recordset from MS SQL Server table.

    - for forms displaying only one record: use ado commands to both read and write.

    here is no plenty of code in internet for this. How to do it via command? It is something like this?

    Dim oConn AsObjectSet oConn =CreateObject("ADODB.Connection")
    Const MYSQL_DRIVER ="{MySQL ODBC 5.1 Driver}"Const MYSQL_SERVER ="10.32.27.6"Const MYSQL_DATABASE ="sales"Const MYSQL_USER ="root"Const MYSQL_PASSWORD ="xxxxxx"oConn.ConnectionString="DRIVER="& MYSQL_DRIVER &";Server="& MYSQL_SERVER &";Database="& MYSQL_DATABASE &";Uid="& MYSQL_USER &";Pwd="& MYSQL_PASSWORD &";"oConn.Open' parameter valueDim lngPartID As LonglngPartID = 12345'

    Create ADODB.CommandConst adCmdText =1Const adParamInput =1Const adInteger =3Dim cmd AsObjectSet cmd =CreateObject("ADODB.Command")

    With cmd
    Set.ActiveConnection= oConn .CommandType= adCmdText
    .CommandText="CALL my_procedure(?)"
    .Prepared=True
    .Parameters.Append.CreateParameter(, adInteger, adParamInput,, lngPartID)
    EndWith

    the stored procedure returns a single delimited string containing the rows.
    fiu fiu here i dont know what to do...Maybe get array from MS SQL Server and split it to the table using loops?

    or with all data as a delimited string that can be passed into a table variable
    Do you have any example for this?

    adodb command either once per row, or in batches where there are enough parameters to handle multiple rows
    Here i please for example...

    I will be very grateful for any tips or sample databases.


    Bulding data models like here seems to me very exciting.

    Thank you in advance,
    Warm Regards,
    Jacek Antek

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    I use Access FE from MS SQL Server BE.
    Tables are linked in.
    It works just fine, no problems.

    Any alterations, I build, then distribute to all users.

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you ranman256.

    Could you please explain where do you create relationships between tables?

    Do you create them in Access FE and in MS SQL Server (in both applications?)

    I would like anyway to test approach which not having linked table to ms SQL Server.
    I am very interesting in it.

    Best Wishes,
    Jacek

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    i started with a self contained access db. tables internal.
    made the relationships.
    then split the db.
    then remapped the backend from Access BE to the SQL BE.
    This way my relationships remained.
    i can swap between the 2 for testing (access) or production (sql)

    Now normally the relationships are in the Access BE and can be viewed in the FE.
    Im not sure if you start with SQL BE that the relations will travel foreward to the FE.
    But you can always build them in the FE, if they dont.
    Last edited by ranman256; 12-20-2017 at 11:01 AM.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I started with a split Access dB. I set up the relationships/RI and life was good. I moved the Access BE off a local computer onto a file server on the network.
    All coding was/is using DAO. Then one table got bigger and bigger (1 million records +). As more and more data was being shuttled across the LAN, things slowed down: the app (forms) slowed down at times and reports got slower and slower.

    So I hear "SQL Server is the way to go. It is much faster". Yes! I installed SQL Server Express as a test. I migrated the tables from the BE to SQLSE 2014, figured out how to use SSMS, re-setup table relationships. Had to learn about and create an ODBC connection..... Re-linked the Access FE to the SQLSE 2014. Oops, now the links have something new. Why do they have "dbo_" as a prefix? Learned I could rename the linked tables. Whew....

    About table relationships and RI. It is not necessary to create table relationships/RI in Access or SQLS. The Access FE will operate just fine. A couple of things you will lose if you don't create table relationships/RI are:
    1) You lose the table auto-join feature when creating multi-table queries.
    2) You lose RI. It will be up to you to ensure referential integrity is maintained.


    OK, there were a few things that had to be fixed due to the difference between Access and SQL data types.
    Then success! FE working great. But..... not any faster. In fact, is seemed even a little slower. All data was still being transferred across the LAN.

    What about ADO instead of ODBC/DAO? Didn't know anything about ADO. Found out if I wrote a FE using C# I could use ADO (not DAO) to connect to almost any database engine.

    Now learning about SQLSE Views and SPs (stored procedures). The advantage of Views and SPs are that the processing of/selecting reccords is done in SQLSE; this means fewer records have to go across the LAN, which means data transfer is faster.
    Did you know you can create a View and link it to the Access FE? And it looks and feels like a table - except you can't add data. But works great for reports. (And you can use a multi-table View as the record source of an Access query.)

    So while SQLSE is "faster" internally generating queries/Views/SPs, you are still limited by your network speed.


    Personally, I would use an Access FE, SQLS/SQLSE and ODBC linked tables (or DSN less connections) as the BE. Learn about Views and stored procedures to reduce network traffic.



    Good luck with your project......

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by ssanfu View Post
    2) You lose RI. It will be up to you to ensure referential integrity is maintained.
    FYI, you can do RI in SQL Server. There may be other ways, but I use triggers (mainly because the old upsizing wizard created them, so now I just copy). I still use code, but it's nice having the data protected.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Paul,

    It is my understanding that if you DON'T set up relationships between table, you cannot have RI enabled.

    Am I missing something? (won't be the first time)
    Can RI be enabled without setting up relationships? (in Access or SQLSE)

  8. #8
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Wow thank you Guys.

    Linked tables and stored procedures sound good to me.

    Here you can read about this:
    https://accessexperts.com/blog/2011/...access-part-1/

    Here Author is recommending to use Adodb recordset to send and get back parameters from SPs or ODBC connection to exchange data between Access and MS SQL Server.

    I found out also that you can use declared tables in SQL Server and thanks to it run it from Access.
    Wow, it is great!

    Still I am looking for more information about this.

    Best wishes,
    Jacek

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by ssanfu View Post
    @Paul,

    It is my understanding that if you DON'T set up relationships between table, you cannot have RI enabled.

    Am I missing something? (won't be the first time)
    Can RI be enabled without setting up relationships? (in Access or SQLSE)
    I'm pretty much self taught. I won't say it's formally RI, nor that it's the best way to go, but you can use triggers to accomplish the same (or similar) goal. You can stop the deletion of a record if there are related records, or delete the related records. You can stop the addition of a record if the FK value doesn't exist, etc. I'm sure a knowledgeable user would say it's a hack, but it's what the old upsizing wizard created.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    pBaldy: by using triggers you can have Referential Integrity (RI) in MS SQL Server?
    It is nice.

    Jacek

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Paul,
    Haven't got to triggers yet.
    Sigh, the reading pile gets bigger and bigger..........

    Thanks for the info.......

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See, there's your problem. You're trying to read and learn, instead of just hacking together workarounds.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664



  14. #14
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hello Guys,

    i have did like Ranman256 said.
    I have tables on MS SQL BE and FE in Access.

    I am linking tables using ODBC connection.

    MS SQL Server is on server so this is network connection.
    Connection is so slow...

    Why ?
    Ranman256 did you run similar database design on network MS SQL Server?

    Please help,
    Jacek

  15. #15
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    I would like to add that my biggest table has 16 mln of rows and has 2 GB space on disc....

    Jacek

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Employee Schedule Database Desgin
    By Bkper087 in forum Access
    Replies: 2
    Last Post: 01-10-2015, 01:41 PM
  2. Which would be more efficient
    By BRZ-Ryan in forum Forms
    Replies: 5
    Last Post: 12-28-2013, 03:41 PM
  3. Most Efficient Way to Accomplish Task
    By cc143most in forum Access
    Replies: 2
    Last Post: 08-24-2012, 02:17 AM
  4. More efficient way to create a query?
    By Kirsti in forum Queries
    Replies: 3
    Last Post: 07-04-2012, 10:36 PM
  5. Efficient Process?
    By compooper in forum Database Design
    Replies: 1
    Last Post: 06-14-2011, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums