SQL Server connection through access VBA - sql-server

History of issue. A colleague built an access database and using VBA made a connection to SQL Server. Then running VBA code made a global temp table ##tablename. this information is used in a passthrough query in the database.
I had to build a new database that uses the same logic. I have everything working except that first part. I am missing something in my code and I am not using code correctly to make that SQL Server connection and run my create global table.
I am not too familiar with this part of coding. I am going to need some hand holding here. I am getting errors no matter what I try.

Related

Adding a view from SQL Server to MS Access

For a school exercise I had to make a view in MS SQL Server and use it for a report in MS Access.
I've made the view in SQL SERVER, but how can I import it into MS Access so that I can use it?
The SQLServer DB is linked with MS Access.
I have made a form for the previous exercise, now I want to make a Report that gives the data from the view I made. I tried using our reader and google, but they are not giving the answer I need. It seems something very simple I am missing out. Just don't get how to update the DB in Access or something, when I make something in SQL Server, it doesn't get added to Access automatically even though I linked them..

BIML OLE DB connection uses the wrong database (sometimes)

I'm using BIML to interrogate the schema of the source and destination databases, check that everything is configured correctly, and then generate a bunch of SSIS packages. My issues is that occasionally the OLE DB connection starts using the Master system database instead of the one I've specified in the connection string. I can tell it is the master database by examining the tables that get returned.
I define the connection using BIML markup:
<OleDbConnection Name="appdb" ConnectionString="Server=<#=ReplicationConfig.appdbHostname#>;Database=<#=ReplicationConfig.appdbDatabaseName#>;Integrated Security=SSPI;Provider=SQLNCLI11;" CreateInProject="true" />
I've hit the issue mostly when trying to use the GetDatabaseSchema() method of the OleDbConnection object on the BIML root node. Though I have also run across it when trying to use an Execute SQL task. It was easy to work around with the Execute SQL task because I could fully qualify the table with [DatabaseName].[schema].[Table] but I don't have that option with the GetDatabaseSchema() method. I've also tried using ImportDB() and GetTableNodes() and they both experience the same issue.
When trying to migrate my solution from the development environment to test the issue has cropped up again. In the past this has been fixed by restarting Visual Studio (or working around it in the SQL query). However, that hasn't worked this time.
I'm using BIML Express with Visual Studio 2015.
Does anyone have any idea what could be wrong or how to get around this?
I ended up working around the issue by setting the default database for my login to the one that I needed to work with. For some reason BIML seems to be ignoring the database specified in the connection string.

VB.NET Application using SQL or Local DB

I'm working on an application and am trying to offer the ability to use a "Local" database or a SQL Server database. What I'm trying to work out is the best Local DB format to use and how to write the queries.
At the moment i have been playing with SQL Server CE and it seems to work fine, but I then need to write each code block twice for any queries (once for SQL and once for SQL Server CE). Is there any solutions to this? Is there some way i can just pass a different connection string?
What i have at the moment is a "sub" that i have a check if using local (my.setting.uselocal) and then call either function Query_SQL or Query SQL. I imagine it will get tiring soon to have to have two blocks for each database query?
Any suggestions on how to do this more efficiently?
Cheers
You could try creating a .sdf file. These can be created programmatically, along with a databse(s)/tables etc in the file.
It's been a long time since I've used them but IIRC you can write read/write with the same tsql syntax. I would have thought it would allow you the same query functions and you can then pass in whatever connection.

Using Access as a frontend for SQL Server and having staging tables

What we do
We run a website that provides statistics. We used to run Access as a backend database, but now made the transition to SQL Server.
How we work
When we receive new statistics we put them in a staging table for proofreading and testing, before exporting them to the live database. Now we are using Access as a frontend for SQL Server with linked tables. This works fine.
What is the best way to having a Access database with staging tables that when ready can be exported to a table in SQL Server? Mind you that the final process should be fairly simple and not technical, as the reason for using Access is the relatively user-friendly UI. Using SQL Server Management Studio would be to technical for the users handling the data.
Let me stress that the solution we need is not a one-time conversion of a table or database, but for staging changes and then pushing them to SQL Server.
Ended up using linked tables and a local staging table which we upsized when the data is ready to be updated on production database.
https://support.office.com/en-us/article/Move-Access-data-to-a-SQL-Server-database-by-using-the-Upsizing-Wizard-5d74c0df-c8cd-4867-8d07-e6e759d72924
Here's some documentation on what I discussed in the comments. If you have never used integration services before the beauty of it is once the import procedure has been created it can be used over and over again.
So once you have the data in excel format, even access if you really wanted to you can follow the steps on the link below
Creating A Simple SSIS Package

Using access 2010 as a frontend to SQL Server database

I am having to develop an application very rapidly. I have chosen SQL Server (2012) as the DB backend, and I will write all my stored procs, triggers etc in the backend.
However, for UI (logon, reporting etc), I am using Access 2010 for the frontend. I am new to both Access used earlier versions of Access waaay back in the day) and SQL Server (familiar with other Db's).
The goal is to have the database reside on a server and let clients connect with an instance of Access 2010 running locally on their machine.
I am looking for a quick tutorial that shows me how to use the SQL server objects from the Access frontend (I believe its called linking) - any link to useful resource would be very helpful, as I can't seem to locate anything useful (I may searching using the wrong keywords).
Assuming you built all the tables and data on SQL server, then in Access it is a simple matter to link Access to that database.
And to save development time, you can continue to use the Access simple approach of using forms bound to those tables. As long as you launch a form with some kind of criteria (say an invoice number), then that bound form will ONLY pull down the one record from SQL server into that form. (so need to write or use store procedures etc. for that form). And any triggers etc. you have built in SQL server will run without you having to do anything from the Access side.
So a plane jane form build in Access that is bound to a table of say 1 million rows in Access does not need any “special” code – just make sure you launch the form with the “where” clause that Access provides and the form will only pull + load the one record.
So 99% of the normal development process you used in Access in the past will continue to work. Using SQL server for the most part does not change much if anything in regards to building forms that edit such data.
However, for reports and some forms that query + search for data etc., or some VBA code that needs to “process” data, you are most free to call store procedures. You simply create a pass-through query in Access. The VBA code to use that T-SQL thus looks like this:
Currentdb.QueryDefs("MyRawt-sqlPassThoughquery").Execute
Or
with CurrentDb.QueryDefs("MyPass")
.SQL = "exec sp_myProc"
.Execute
end with
In the past for most access applications you likely used liked tables – those linked tables can be to a Access file (back end), or Oracle, or SQL server – how the actual application works and functions is really much the same for all cases. (so there not really a lot of “specific” things you need to know from the Access side – if you comfortable with Oracle, or SQL server, then using Access as a front end works just fine, and the typical development approaches used in Access will remain typical.
Here is an article that outlines the linking process:
https://support.office.com/en-us/article/Import-or-link-to-SQL-Server-data-A5A3B4EB-57B9-45A0-B732-77BC6089B84E?ui=en-US&rs=en-US&ad=US&fromAR=1
Keep in mind you will see MANY articles that talk about ADP projects - they have been deprecated since Access 2010, and I don't recommend using ADP projects with Access - so be careful, since many articles that talk about Access + SQL server are built around ADP projects which as noted should not be used anymore.
This office.microsoft.com article should give you a good overview.
With plenty of more technical information searching for "query sql server from ms access".
Don't mess about with linked tables. Use an Access ADP (Access data project), which is natively connected to SQL Server. Sadly this type of access file is being phased out but it is the optimal solution for an MS Access front end with a SQL Server back end
Pros and Cons of Access Data Project (MS Access front end with SQL Server Backend)

Resources