Expose Microsoft Access database over SQL Server using linked server - sql-server

We have one .exe application that uses one .mdb Microsoft Access database.
I need to access data inside access file over Microsoft SQL Server. We have SQL Server 2008 R2 Enterprise that has linked server pointed to this Access file and I can run select / update query using SQL statement.
SELECT * FROM [LinkedServerAccessDB]...[SomeTable]
How can I configure that this linked server, my Access database, is directly published as "Database" when some application tries to connect to my SQL Server using SQL Server instance name, and username and password. Which "database name" should I use to use directly linked server ?
Thank you

It sounds like you want your MS Access Linked Server object available as a database (i.e. available in the 'Databases' folder in SSMS). This isn't possible, directly.
Suggest you create a new SQL Server database that mimics the name of that Access database. Map a user to that login you've got above. Allow the user to run queries against the linked server.

You can use CREATE SYNONYM like so.
USE ASQLServerDB
GO
CREATE SYNONYM Sometable FOR LinkedServerAccessDB...SomeTable
Once this is done you can write SELECT [...] from SomeTable as though it was a member of the database ASQLServerDB
I was only able to get it to work at the object level so you'll need to do this for each object you want to expose. You could create an empty database that just contained these Synonyms if you wanted to get that "published as a database" feel.
--This doesn't work
CREATE SYNONYM Sometable FOR LinkedServerAccessDB...

Related

Azure SQL - How to skip USE statement in Azure SQL while having it work in SQL Server

I am trying to update an old script in a production installer so that it can work with both Azure SQL and SQL.
The problem is that our script is calling USE to switch the database. On prem we are creating the database, in Azure it will already be created for us... so we are detecting its existence and moving on. However that is where we are then calling USE to switch, for on prem.
I was hoping I could skip it like this in Azure
IF NOT SERVERPROPERTY('edition') = 'SQL Azure'
USE MYDB
I am still getting the "USE statement is not supported to switch between databases."
The hack is to put this into a string and run it with: EXEC sp_executesql
This works for most things, but I don't think it works with the USE statement.
Is there any way I can let the Azure SQL parser skip this section, as it will never be executed?
I am open to SQL based workarounds... but I am trying to avoid rearchitecting the installer.
USE statement is not supported to switch between databases
On Azure SQL Database this error only occurs when you try to 'USE' a different database.
In Azure SQL Database, the database parameter can only refer to the
current database. If a database other than the current database is
provided, the USE statement does not switch between databases, and
error code 40508 is returned.
USE (Transact-SQL)
Similarly three-part names referencing the current database are allowed.

Azure SQL and Visio 2019 Plan 2 Database Reverse engineering wizard Fails

Screenshot of ErrorI am using Visio 2019, trying to reverse engineer a Azure SQL server. I have successfully created multiple User data sources to use in the wizard using both our DB-admin user and my admin azure directory logins. The database credentials are successfully verified and the tables/views i want to reverse engineer are about to load in when i get the following:
Visio reverse engineer database wizard raises error:
"Error! Cannot extract column definition for the table/view . The definition is not
available or you may not have sufficient privileges."
with a text box that says:
"Could not find server "database name"* in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers."
I can neither find sys.servers nor run sp.addlinkedserver as it does not exist. though, sys.sysservers does exist.
I starred database name since instead of showing the target DB of "DB_2.0" it shows "DB_2" which is not the full name of the Database.
As i mentioned above i believe that i have sufficient privileges as i have tried both the admin username and password and my admin login using azure directory. So it may have something to do with not having the sys.servers table?
Is there a way to create the sys.servers table or create the stored procedure sp.addlinkedserver as Visio is requesting? Is it advisable to do is Azure SQL, could the naming convention of our DB have anything to do with the error?
Worked with MSFT support, they had me rename my database from DB_2.0 to DB_2. I created a new connection DSN and it worked perfectly afterwards. Apparently visio doesn't like the ".0" in a connection string. It would be nice if i could have eddited the connection string in a text file so I did not have to rename my entire DB.

Use SQL Server database table as to configure SSIS project parameters and variables

We would like to use a SQL Server table as a source for all connection manager values within SSIS. We would prefer to do this at the project level since many of our connections are already at the project level. We would like to be able to easily switch which environments we are looking at based on an input value when the project opens. The reason we need to do this is because when creating our projects in dev we use different connections than when deploying them to prod, and we have hundreds of different connections being used. We don't want to have to switch anything in SSIS or in SQL Server Agent or the SSIS Catalog. We would love for these to be strictly maintained within a SQL Server table.
How can we have these values fed from a SQL Server table into variables that feed the values or parameters? To reiterate, the end product would have 1 single table in SQL Server that contains all columns like [ConnectionString], [InitialCatalog], [UserName], [UserName], [Password], [HeaderRowsToSkip] etc. We would parameterize all connection managers that would have their values fed from this table. We need direction on how to accomplish this.
I would like to be able to contain both PROD and DEV in the same table with an [Environment] column that has a value of 'Dev' or 'Prod', and if possible we would like to have a prompt open when the Project opens in SSIS that asks which [Environment] we would like (A fillable prompt) that would in turn filter the results from the SQL Table to use either Dev or Prod based on what we enter.
If 2) is not possible, we would just use separate tables that could be switched in the connect manager manually based on when we are developing or deploying.
It sounds exactly the same as what "Environment Variables in SSIS Catalog" does!
The "Environment" in SSIS Catalog works like a configuration file for parameters, in your case, you can create Prod/Dev Environment, and map the variables in it to the Project Level parameters, which are mapped to Project Level Connection Managers.
Reference:
Setup Environment Variables in SQL Server Integration Services
Creating a Robust SSIS Development Environment using the SSIS Catalog
Apart from the discussion about how much securely is (a password inside a SQL Server Table, really?), I had made this kind of request using a special combination of PowerShell and in some cases getting info from Servers from SQL Table, for this, you can use a SQL Script Task Editor:
SELECT instanceName,databaseName,DataSource
FROM meta.InfoSSIS
WHERE environmentName = ? --Input parameter corresponding to DEV, INT or PROD
The output of this Query should be feeding the object, for instance, User: DatabaseList which is basically a DataType: Object and which store the info for SSIS instance, DB name, and DataSource. Internally you can have a ForEach Loop object which allows to interact with the DatabaseList object and work on it.

how to mirror a whole database cluster in postgresql

I'm using a postgresql (9.6) database in my project which is currently in development stage.
For production I want to use an exact copy/mirror of the database-cluster with a slightly different name.
I am aware of the fact that I can make a backup and restore it under a different cluster-name, but is there something like a mirror function via the psql client or pgAdmin (v.4) that mirrors all my schemas and tables and puts it in a new clustername?
In PostgreSQL you can use any existing database (which needs to be idle in order for this to work) on the server as a template when you want to create a new database with that content. You can use the following SQL statement:
CREATE DATABASE newdb WITH TEMPLATE someDbName OWNER dbuser;
But you need to make sure no user is currently connected or using that database - otherwise you will get following error.
ERROR: source database "someDbName" is being accessed by other users
Hope that helped ;)

How to move SQL Server Database to another?

Originally, I created my database using SQL Server Management Studio on my local machine.
I now want to copy it into my App_Data in my web site folder, and in this way I hope to move my web site freely, meanwhile moving my database which contained in my App_Data to the other machine.
What steps should I follow?
I'm using SQL Server 2008 Express.
There are many way to transfer running database.
Using backup restore. refer microsoft
Using Replication.
Detach and Attach is not the right way because there is chance of data loss.
There are many ways to move/copy a database from one server to another server using SQL Server Tools.
i) Detach the database from the old server and attach it in the new server. This is purely offline operation and it moves the database instead of copying it.
Refer http://msdn.microsoft.com/en-us/library/ms190209.aspx : how to use attach/detach database in SQL Server Management Studio(SSMS)
ii) Back up the database in the old server and restore it in the destination server. This can be performed during online and it creates a new database in the destination server.
Refer http://msdn.microsoft.com/en-us/library/ms187048.aspx for more information.
iii) Using copy database wizard in SQL Server Management Studio.
Select the database in the source server in SSMS
Right click ->Tasks->Copy Database Wizard to launch the copy database wizard.
Enter the source and destination credentials and select either attach/detach or SMO type
click next and you can schedule or run immediately
Click finish to execute it
Refer http://msdn.microsoft.com/en-us/library/ms188664.aspx for more information.
iv) The last type is to generate the create script using Generate Script Wizard (SSMS) and execute it in the destination server.
Select the database in the source server in SSMS
Right click ->Tasks->Generate Scripts Wizard to launch the wizard.
Select the various scripting options needed and select the objects needed to generate the scripts for them. Make sure script data = true in the scripting option to generate script for data as well (INSERT statements)
click next ->next and finish to generate the script (new query window or clip board or file)
connect to the destination server and create the new database in it.
Click new query window and paste the script generated using GSW above and execute them with the destination database context.
Refer http://msdn.microsoft.com/en-us/library/ms181421.aspx for more information
v) Using Transfer Object in SMO
Sample code:
ScriptingOptions so = new ScriptingOptions();
so.ScriptData = true;
Transfer t = new Transfer(db);
t.CopyAllObjets = true;
t.options = so;
...................
..................
t.TransferData();
Note: Transfer class is available in Microsoft.SqlServer.SmoExtendedClass.dll (SQL Server 2008)
or Microsoft.SqlServer.Smo.dll (SQL Server 2005)
There are various member variables to be configurable. Also ScriptingOptions class object can be created and assigned to the transfer object as well.
set ScriptData = true in order to transfer data also. It copies the destination instead of moving the database
Refer http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.transfer.aspx for more information.
vi) You can make use of Database Publishing Wizard to accomplish this. You can specify the target version as SQL 2005 or SQL 2000 etc as per your requirement.

Resources