Is it possible to use different Oracle schemas in Crystal Reports and change between them at runtime?
I have a report that uses three tables. The report was created using one database user schema. In the other schemas that I have to use, the names of the tables are the same. I need to change between them at runtime. Different users get different data depending on the schema they connect to. I set the servername, the userid, the password and then integratedsecurity to false. If I change/set the DatabaseName it doesn't work.
I use Crystal Reports 2008.
Could you be kind and help me with this?
Thank you very much !
Don't use Crystal's database expert - instead, write SQL queries that do not specify schema. That way, the query will access the tables in the local schema when logged on to it.
eg:
Existing query:
select field1, field2, ...
from user_schema1.datatable
- will select data from user_schema1.datatable, regardless of which schema is logged on.
Amended query:
select field1, field2, ...
from datatable
- will select data from datatable in user_schema1 when logged on to user_schema1, from user_schema2 when logged on to user_schema2, etc.
Related
I want to do what SQL MERGE...WHEN MATCHED...WHEN NOT MATCHED does,
but with the source and destination tables on different Azure databases. (Typically on the same server if that helps.)
The source and destination tables are not exactly the same, that's why SQL MERGE would be perfect. (I can decide what column to match on, and which columns to use in the INSERT or UPDATE.)
If this can not be done in SQL, I could load the tables into my C# code and do the merge there (will affect performance though). Does anyone know if .NET has something similar to SQL MERGE in ADO.NET (merging DataTables).
Thanks for any help!
Edit: this image shows the tables before MERGE (all Values are int):
This image shows the MERGE statement and the resulting source and dest:
Azure SQL database doesn't support across database operations directly, even these databases are in the same Azure SQL Server. it will throw below error.
To work around this Azure SQL database only support the across database query with elastic query
Example
CREATE MASTER KEY; -- create master key
GO
-- credential maps to a login or contained user used to connect to remote database
CREATE DATABASE SCOPED CREDENTIAL CrossDbCred1 -- credential name
WITH IDENTITY = 'username', -- login or contained user name
SECRET = '**********'; -- login or contained user password
GO
-- data source to remote Azure SQL Database server and database
CREATE EXTERNAL DATA SOURCE source
WITH
(
TYPE=RDBMS, -- data source type
LOCATION='server.database.windows.net', -- Azure SQL Database server name
DATABASE_NAME='database1', -- database name
CREDENTIAL=CrossDbCred1 -- credential used to connect to server / database
);
GO
-- external table points to table in an external database with the identical structure
CREATE EXTERNAL TABLE [dbo].[source]
(
[Id] [varchar](50),
[value1] [int],
[value2] [int],
[value3] [int]
)
WITH (DATA_SOURCE = [source], -- data source
SCHEMA_NAME = 'dbo', -- external table schema
OBJECT_NAME = 'source' -- name of table in external database
);
GO
Now we can test our Elastic Query to merge tables.
MERGE into destination1 B
USING source E
ON (B.Id = E.Id)
WHEN MATCHED THEN
UPDATE SET value2 = E.value2, value3 = E.value3
WHEN NOT MATCHED THEN
INSERT (Id,value2,value3) VALUES (Id,value2,value3);
Output
Before merging
After merging
I have an Azure SQL (S3) geo-replicated read-only database.
My problem is that when I query the Read-only from VisualStudio I can see the Query is hitting the Master database.
I expect the Query to hit the Read-only database.
But if I run the same Query from SMSM connected to Read-only then I can see the Read-only database is hit. This works as expected.
To see the last Query in each database I use following SQL.
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC
Question
Why is my c# (entityframework 6.0) code not showing in the Read-only database?
Background
The goal is to have a read-only SQL to handle the external API load so the Master SQL is not to load.
In Azure Portal, I created a Geo-Replication SQL in the same region as Master.
The connection string is set to Read-only database.
I tried[ApplicationIntent=ReadOnly] flag in connectionstring with no success.
The problem was old format on the connectionstring "User ID".
I used "username#server". The #server was pointing to the server of Master Sql.
I changed to only "username" and now it works.
I have two databases one for testing and one for production for example database and database_test, I set the connection string to connect to database_test, I don't know, why when I try to access to any row of one table the query generated add the database production name for example database.TableName and in the other tables only generate a query with TableName without the databaseName. I try adding a schema in a table name in the model but always is adding the database name that it's the production name, instead of generate the queries without database name, why it's this behavior?
Update: sorry is EF Core 2.2 from mysql with pomelo, the connection string database is testing, the production database name is production. For example the next code
contexto.Table1
is translated in a query select * from production.Table1 instead of only translate in Select * from Table1
My query is when I install this application on some system with SQL Server install I should get all databases in a combobox.
Login image
In the first combobox (Select database type) we have option to select the SQL Server. When I will select the SQL Server, I wish that the available instance of the database like root or something else should come in second combobox. And we should get the database name of the all database in the 3rd combobox
To list the instances of Sql Server you can use:
SQLCMD -L
By executing it in a process and collect the output.
For listing of the databases you can use this select statement:
SELECT name FROM master.dbo.sysdatabases
or
EXEC sp_databases
The problem is, you need to be logged in to the database to get the list of databases which the logged in user is allowed to see. I think you need to consider it in your application.
i have an idea to call two values from two different databases and comapre them in one statement? is it possible?
i am working with c# and MS-SQL
Yes.
For MSSQL you can add the database name in front of your table. You normally have 4 namespaces you can use
[Server name].[database name].[owner].[table_name]
So if you want to compare two values in the one statement you should only need to join across the tables by placing the database name in front of the table name.
If the databases are on different servers then you will need to create a linked server to the side which will run your SQL so that its aware of the other sql server. You can add linked servers in Management studio or via SQL using something like sp_addlinkedserver
You may do cross database joins to compare these values:
SELECT
db1.Value as value1,
db2.Value as value2
FROM
[database1].dbo.MyTable1 as db1
INNER JOIN
[database2].dbo.MyTable as db2
ON
/* insert join clasue */
There are a few possibilities here depending on your setup. If your databases are different SQL Server installations then you will want to look at sp_linkedserver first. Once you have the ability to see both databases using the same login you could just execute the following query where db1 and db2 are the databases, dbo is the owner and tab1 and tab2 are the respective tables.
SELECT a.col1
FROM db1.dbo.tab1 a, db2.dbo.tab2 b
WHERE a.col1 = b.col2
If you should happen to lack the SQL Server permissions to create a linked server, you could create connections to each server and your client could attach to the servers using Microsoft JET library, and then you could perform the heterogeneous join client-side.