Ms Access Join tables in separate databases in delphi - database

I use ADOConnection and AdoQuery to execute queries over MS Access (mdb) database. I want to join two tables in different databases (mdb files). I searched the web and find this solution:(example)
select [ZRDocs].* from [ZRDocs] left join [;database=d:\2222.mdb].[ZRDocItems] AS abc on [ZRDocs].[ID] = [abc].[DocID];
when I query this inside MSAccess, It works fine but when I execute this using ADOQuery, it throws an exception :
Parameter object is improperly defined. Inconsistent or incomplete information was provided.
I use Microsoft.Jet.OLEDB.4.0 provider.
I also used complete connection string like this:
select [ZRDocs].* from [ZRDocs]
left join [Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=d:
\2222.mdb;Mode=Share Deny None;Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;].[ZRDocItems] AS abc
on [ZRDocs].[ID] = [abc].[DocID];
I searched google and many pages but found nothing.
So, how join two tables from different mdb (access) databases using delphi (ADO)?

Try this code:
select [ZRDocs].*
from [ZRDocs] left join ([ZRDocItems] IN "D:\2222.mdb") AS abc
on [ZRDocs].[ID] = [abc].[DocID];

Related

Mailmerge result not displaying after connecting it with a database

I have a mailmerge that I am currently developing. I connected the mailmerge to a database (a particular query in the database) as datasource but I see nothing if I press Alt+f9. I understand that ctrl A and pressing F9 is for refreshing the data but it is still not working. Strangely it was showing before
Below is the mailmerge jargons when I toggle back:
DATABASE \d "X:\\PM\\PM-O\\PM-OQ\\PM-OQRA\\PROCESSES\\02_Cosmetics\\98_ Database\\99_Release\\Dossier_Developer.accdb" \c "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=X:\\PM\\PM-O\\PM-OQ\\PM-OQRA\\PROCESSES\\02_Cosmetics\\98_ Database\\99_Release\\Dossier_Developer.accdb;Mode=Read;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False" \s "SELECT * FROM Q_DOSSIER_LeapingBunny_S_C01_ConnectArticleNo" \l "16" \b "191" \h

How to point ALL deployed SSRS reports to different shared datasource on report server?

I have more than a hundred deployed reports on a report server that basically using same shared datasource.
Now I need to repoint all of them to a different datasource.
So I am manually going through each report on a report server and pointing it to a different shared datasource.
Is any way to do that for all reports at once?
This is not a full answer but I think it points you in a direction that might get you unlocked:
I would check into the ReportServer database. I think there appear to be 2 relevant tables. [DataSource]
and
SELECT SDS.name AS SharedDsName
,SDS.[Path]
,CONVERT(xml, CONVERT(varbinary(max), content)) AS DEF
FROM dbo.[Catalog] AS SDS
WHERE SDS.Type = 5
I found a great query that hints at this here:
https://gallery.technet.microsoft.com/scriptcenter/List-connection-strings-of-1a9a9adc
That query is:
-- List connection strings of all SSRS Shared Datasources
;WITH XMLNAMESPACES -- XML namespace def must be the first in with clause.
(DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource'
,'http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'
AS rd)
,SDS AS
(SELECT SDS.name AS SharedDsName
,SDS.[Path]
,CONVERT(xml, CONVERT(varbinary(max), content)) AS DEF
FROM dbo.[Catalog] AS SDS
WHERE SDS.Type = 5) -- 5 = Shared Datasource
SELECT CON.[Path]
,CON.SharedDsName
,CON.ConnString
FROM
(SELECT SDS.[Path]
,SDS.SharedDsName
,DSN.value('ConnectString[1]', 'varchar(150)') AS ConnString
FROM SDS
CROSS APPLY
SDS.DEF.nodes('/DataSourceDefinition') AS R(DSN)
) AS CON
-- Optional filter:
-- WHERE CON.ConnString LIKE '%Initial Catalog%=%TFS%'
ORDER BY CON.[Path]
,CON.SharedDsName;

How table was created in SQL-Server

What I need to find is the procedure of recreating some table, what data sources were used, which scripts if any &c. So is it possible to differentiate somehow, maybe in system views or similar, if the table was created manually or by query and if the data was imported from external data or from already existing table/view in the database? I already know who created and when. I’ve pretty much screened whole database without results and now I am looking for hints in metadata.
If the table was created recently, you can glean information from the default trace. The query below will list object created and altered events. The default trace is a rollover trace so forensic information will be limited based on activity.
SELECT
trace.DatabaseName
,trace.ObjectName
,te.name AS EventName
,tsv.subclass_name
,trace.EventClass
,trace.EventSubClass
,trace.StartTime
,trace.EndTime
,trace.NTDomainName
,trace.NTUserName
,trace.HostName
,trace.ApplicationName
,trace.Spid
FROM (SELECT REVERSE(STUFF(REVERSE(path), 1, CHARINDEX(N'\', REVERSE(path)), '')) + N'\Log.trc' AS path
FROM sys.traces WHERE is_default = 1) AS default_trace_path
CROSS APPLY fn_trace_gettable(default_trace_path.path, DEFAULT) AS trace
JOIN sys.trace_events AS te ON
trace.EventClass=te.trace_event_id
JOIN sys.trace_subclass_values AS tsv ON
tsv.trace_event_id = EventClass
AND tsv.subclass_value = trace.EventSubClass
WHERE te.name IN(N'Object:Altered', N'Object:Created')
AND tsv.subclass_name = 'Commit'
ORDER BY trace.StartTime;

Cross db permission issue

I have 3 databases on the same SQL Server 2012:
- erpCountry1
- erpCountry2
- erpWeb
erpWeb database was built to allow a special user (webUser) to read some data from outside. It is mostly a few views like this (simplified version):
create view erpWeb.dbo.vwClients
as
SELECT 'XX' as Region, IdClient, Nom, Adress
FROM erpCountry1.dbo.Clients
UNION ALL
SELECT 'YY' as Region, IdClient, Nom, Adress
FROM erpCountry2.dbo.Clients
Currently the user webUser must be mapped to erpCountry1 and erpCountry2 databases, otherwise view erpWeb.dbo.vwClients does not work for him.
My question is: what should I do to allow webUser to see the result of vwClients WITHOUT mapping webUser as datareader for erpCountry1 and erpCountry2 ? (since this allows webUser to see all data of those databases)
Edit: in Access, you can define a query to run with owner's permissions (instead of user's). Isn't there anything equivalent in SQL Server ?

How to create VIEW in MS Access Database using Delphi Application without installing MSAccess on PC?

I want to create VIEW definitions on MS Access. I have used following CREATE VIEW Statement:
SELECT
MFP.FollowUpPlan_Id,
MFP.FollowUpPlan_Name AS PlanName,
DFP.Sequence_No AS SequenceNo,
MFS.FollowUpSchedule_Name AS ScheduleName
FROM
MAS_FollowUp_Plan AS MFP,
DET_FollowUp_Plan AS DFP,
MAS_FollowUp_Schedule AS MFS
WHERE
(((MFP.FollowUpPlan_Id)=DFP.FollowUpPlan_Id) AND
((DFP.FollowUpSchedule_Id)=MFS.FollowUpSchedule_Id)) AND
MFP.is_Deleted = FALSE AND
DFP.is_Deleted = false
ORDER BY
MFP.FollowUpPlan_Id, DFP.Sequence_No;
but it throw an error:
Only Simple Select Queries are allowed in view.
Please Help, Thanks in Advance.
The issue here, as Jeroen explained, is a limitation of Access' CREATE VIEW statement. For this case, you can use CREATE PROCEDURE instead. It will create a new member of the db's QueryDefs collection --- so from the Access user interface will appear as a new named query.
The following statement worked for me using ADO from VBScript. From previous Delphi questions on here, my understanding is that Delphi can also use ADO, so I believe this should work for you, too.
CREATE PROCEDURE ViewSubstitute AS
SELECT
MFP.FollowUpPlan_Id,
MFP.FollowUpPlan_Name AS PlanName,
DFP.Sequence_No AS SequenceNo,
MFS.FollowUpSchedule_Name AS ScheduleName
FROM
(MAS_FollowUp_Plan AS MFP
INNER JOIN DET_FollowUp_Plan AS DFP
ON MFP.FollowUpPlan_Id = DFP.FollowUpPlan_Id)
INNER JOIN MAS_FollowUp_Schedule AS MFS
ON DFP.FollowUpSchedule_Id = MFS.FollowUpSchedule_Id
WHERE
MFP.is_Deleted=False AND DFP.is_Deleted=False
ORDER BY
MFP.FollowUpPlan_Id,
DFP.Sequence_No;
You cannot mix ORDER BY with JOIN when creating views in Access. It will get you the error "Only simple SELECT queries are allowed in VIEWS." (note the plural VIEWS)
Having multiple tables in the FROM is a kind of to JOIN.
either remove the ORDER BY,
or have only one table in the FROM and no JOINs.
I remember from the past (when I did more Access stuff than now) seeing this for a large query with a single table select with an ORDER BY as well.
The consensus is that you should not have ORDER BY in views anyway, so that is your best thing to do.
Another reason that you can get the same error message is if you add parameters or sub selects. Access does not like those in views either, but that is not the case in your view.
Declare variable olevarCatalog ,cmd as OleVariant in Delphi, Uses ComObj
olevarCatalog := CreateOleObject('ADOX.Catalog');
olevarCatalog.create(YourConnectionString); //This Will create MDB file.
// Using ADO Query(CREATE TABLE TABLEName....) add the required Tables.
// To Insert View Definition on MDB file.
cmd := CreateOleObject('ADODB.Command');
cmd.CommandType := cmdText;
cmd.CommandText := 'ANY Kind of SELECT Query(JOIN, OrderBy is also allowed)';
olevarCatalog.Views.Append('Name of View',cmd);
cmd := null;
This is a best way to Create MS ACCESS File(.MDB) and VIEWs using Delphi.

Resources