SSRS report builder 2.0 How to link 2 servers and run in one dataset - sql

I am trying to find a way of linking data from two servers in SSRS report builder 2.0
ultimately using one dataset to query 2 databases in 2 different servers.
The SQL that i have is very basic as shown below and i can run the query easily in SQL management studio.
select * from
[server1].[DES].[dbo].[Daily] dr
LEFT JOIN [server2].[VES].[dbo].[Rou] mr
ON dr.ID = mr.id
Also the access i have to the reporting server is read only so i cant really make any administrative changes to the configuration.
I have explored the connection string to create a connection but it only allows me to connect to one server for each dataset. what i am trying to do is use one dataset
Any help will be greatly appreciated as i am a junior in SQL and SSRS
Using SSRS and MS SQL 2008 R2

if you executing this query from your SSMS it means this other server
is a linked server. then it should be no different to execute it from
SSRS.
Yes it is right you can only add one server to your data source of
your dataset whether its a shared data source or embedded.
But for instance if you have a data source pointing to say Server A
when you executing queries which will be pulling data from Server A
and also from server B you will Use fully Qualified name for the
Objects from server B and two part name from server A.
something like this ...
SELECT *
FROM Schema.Table_Name A INNER JOIN [ServerNameB].DataBase.Schema.TableName B
ON A.ColumnA = B.ColumnA
obviously ServerB has to be a Linked Server.

I can think of two possible solutions
Option 1:
Creating a stored procedure on server1 (With a query accessing the another server). And call this stored procedure from SSRS (Dataset).
Option 2:
Create two dataset with two different connection strings on the RDL (one for Server1 and another for Server2).
Use the "LookUpDataSet" function in Report Builder to merge the results using the key fields.
Option 2 is preferable.

Related

Query tables between two different servers in SQL Server

I have two databases, one in SQL Server and one in Azure SQL Synapse. Now I want to have one single query that should be done between two tables from these different servers.
For example:
SQL Server name : server1
Database name : db1
Table name : tb1
Azure Synapse name : prod-synapse-2
Database name : db2
Table name : tb2
Now query should be like this:
select
tb1.col1, tb1.col2, tb2.col3, tb2.col4
from
tb1
outer join
tb2 on tb1.col5 = tb2.col5
The above query is very simple to join two tables from the same database or two tables from the 2 different database within same server.
But I want suggestions to have the above query between 2 different servers.
I have seen in many stackoverflow questions similar to this, they suggested an answer using Linked Server, but that cannot be done in my case, because I will not be provided with access to create Linked server, and link the 2 servers in Microsoft SQL Server Management Studio.
Thanks in advance
Another way to query a database hosted in a remote SQL Server is the OPENROWSET T-SQL function. To use the OPENROWSET ad hoc method, you need to provide all connection information that is required to connect to the remote SQL server and many other resources.
Using OPENROWSET requires enabling the Ad Hoc Distributed Queries advanced configuration option same as the OPENDATASOURCE function.
You need to provide the provider’s name, the connection string and the query as follows:
OPENROWSET(‘providername’,’datascource,’query)

Multiple server SQL query in .Net

I have a query that currently runs successfully on SQL Server Management Studio, gathering information from 2 databases on the SQL server where I run the query, and one database on a linked SQL Server. The query has this structure:
SELECT TOP 10
DB1.id_number as BLN,
DB1.field1,
DB2.field2,
DB3.field3
FROM
LinkedServer.database1.dbo.table1 DB1
INNER JOIN
database2.dbo.table2 DB2 ON DB1.id_number = DB2.id_number
INNER JOIN
database3.dbo.table3 DB3 ON DB3.id_number2 = DB1.id_number2
WHERE
DB1.id_number IS NOT NULL
AND DB1.field1 IS NOT NULL
How can I run this same query from a .Net application? I am looking for a solution that doesn't require saving a View on the database.
In whatever solution you propose, please detail connection strings and security issues.
Thank you.
You can run the query using SqlCommand. Although doing it with an ORM may be a little tricky, if it even can be done.

For a Front end access user interface connected to a backend SQL server, do I create new queries for tables in the SQL server or Access frontend?

I am a new database intern working with a access front end and SQL server backend database. The database was custom made for the company. One of my assignments is to take scripts and apply them to make four new tables. I am aware that I need to make a new query for each new table but I don't know if I should make the query in SQL server management studio or the frontend access program. I have tried copying and pasting the given scripts into a new query in access but I get an error message "invalid SQL statement expected 'DELETE', 'INSERT'...". I decided to try to break done the program a little bit and tested the first line
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =OBJECT_ID(N'[dbo] .[FK_tblInstrumentInterfaceLog_tlkpInstrument]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblInstrumentInterfaceLog]'))
but the same error message keeps popping up. I even tried just SELECT * FROM sys.foreign_keys, and I got the error message "could not find file...". I am very much a beginner and any guidance would be appreciated.Basically am I supposed to be applying these scripts the server SQL database or on the front end access program?
Are you using a pass-through query? i.e. not just a select query. Access needs to know where to send the query and since you are using TSQL not Access SQL this needs to be executed on the server.
Normally when you query a linked table the information of how to get the data (the connection string) is tied to the table. But for this kind of query you'll probably need to tell Access explicitly. Unless you are using an ADP/ADE, then the connection info travels with the program not the table.
As a general rule, you use SQL management studio (SSMS) to create and run those scripts. So the general accepted approach here is such scripts will not be placed in the front end. As noted such scripts if for some reason must be placed in the front end, then you have to create them as pass-though, but EVEN in this case you want to use the SSMS to create such quires.
So the answer here is you create the new scripts and make table queries in the back end, or in this case using the SQL server management studio.
The syntax checking, query editor etc. in recent versions of SSMS now has auto-complete etc. and you can test/write/update those scripts in SQL server. Once you have such a query or even several of them, then the resulting “several” statements can be pasted into a front end query that been created as pass-though. If you do not use a pass-though query, then you are creating and using and assuming client side SQL (JET (now called ACE)).
The client side has it own version of SQL syntax, and it is NOT 100% compatible with the SERVER SIDE. If you writing SQL in the client that is NOT pass though, then you using a linked table to SQL server. These linked tables thus will use local (JET/ACE) based SQL queries. The ODBC driver thus translates this SQL into server side compatible syntax. However the JET/ACE sql syntax is very limited when compared to SQL server and no server side commands exist in this SQL syntax for the client data engine (JET/ACE)
So for many quires, you will and can simply build such queries using the Access query builder.
However for SQL that needs to run 100% server side then such quires has to be setup as pass-though and are in most cased built + tested using SSMS.

ADO to query MDB and SQL Server

I've got a database that resides on an SQL server box, and another in a separate mdb file.
Both contain similar data, but I'd like to run a query that checks unmatched records from a field that exists in both.
Is this something that's easy enough to do using ADO (VBA)? If so can you point me in the right direction?
The easiest would be to create a new Access Database or ADP, and link the tables from both the SQL server and the other MDB. That way you've got an interface to both from within the same instance, which allows you to query or join different tables.

How to create views based on tables from different server?

How to create a view from table A from server 1 and table B from server 2, based on a same column named as col? They use different credentials. The servers are SQL Server 2005
Without knowing details, I'm not sure this is the best idea - but this would work for you. It requires four part naming and linked servers.
Here is the syntax for the view.
Create VIEW [dbo].[vw_CrossServer]
AS
SELECT *
FROM Server1.DatabaseName.Schema.tableA TA
INNER JOIN Server2.DatabaseName.Schema.tableB TB ON TA.col = TB.col
GO
For this to work, you'll need to setup a linked server between the databases. Linked Server
Link also contains examples and other resources.