Thursday, March 8, 2012

Connecting to another database

In a SQL Server database, there are views based on the tables from another
database on the same server. Is it possible that when the users open these
views (through the Web pages) they are connected to the database2 under
another login (not the login which is used to connect to the current
database)?
Thanks.
Hi Vik,
What is the purpose of this? If your web application connects to database2,
the view is not going to be the present there and you need to use
database1..view to connect to the view.
And if you want the web app to connect to database 2 under another login,
that has to be defined in your application's connection string.
Thanks
Yogish
|||No, if you SELECT from a view then you use the same connection. Of course, the application
programmer might have written the application so that it opens another connection using another
login...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:OKVKhUqEFHA.3984@.TK2MSFTNGP14.phx.gbl...
> In a SQL Server database, there are views based on the tables from another database on the same
> server. Is it possible that when the users open these views (through the Web pages) they are
> connected to the database2 under another login (not the login which is used to connect to the
> current database)?
> Thanks.
>
|||In the db1, there are:
Table1,
View1 based on the db2 (should be read only),
View2 based on the Table1 and View2. The Web page is based on the View2,
that is the page connects to both databases using one connction string.
The users of the Web page log in with their own userid, and these logins
exist in the db1 as we need to record (using the triggers) which user
entered/modified data.
The users of the db1 need read-only access to the db2 (through the View1)
and could use one common login to the db2 as the db2 does not need to know
who connected to it with read-only access.
So, I wanted to use one datareader login in the db2 instead of creating the
logins in the db2 for each user of the db1. I supposed there may be a way to
specify a connection to the db2 in the View1 itself.
Thank you.
Vik
"Yogish" <yogishkamathg@.icqmail.com> wrote in message
news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
> Hi Vik,
> What is the purpose of this? If your web application connects to
> database2,
> the view is not going to be the present there and you need to use
> database1..view to connect to the view.
> And if you want the web app to connect to database 2 under another login,
> that has to be defined in your application's connection string.
> --
> Thanks
> Yogish
>
|||You should read about ownership chains and also about "Cross DB Ownership Chaining". If you don't
want the users to exists in the db where the table resides, you need to turn on cross database
ownership chaining. But you also need to make certain that you have proper owner for the tables and
views (so you don't get a broken ownership chain).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:eAu2TTrEFHA.392@.TK2MSFTNGP14.phx.gbl...
> In the db1, there are:
> Table1,
> View1 based on the db2 (should be read only),
> View2 based on the Table1 and View2. The Web page is based on the View2, that is the page connects
> to both databases using one connction string.
> The users of the Web page log in with their own userid, and these logins exist in the db1 as we
> need to record (using the triggers) which user entered/modified data.
> The users of the db1 need read-only access to the db2 (through the View1) and could use one common
> login to the db2 as the db2 does not need to know who connected to it with read-only access.
> So, I wanted to use one datareader login in the db2 instead of creating the logins in the db2 for
> each user of the db1. I supposed there may be a way to specify a connection to the db2 in the
> View1 itself.
> Thank you.
> Vik
>
> "Yogish" <yogishkamathg@.icqmail.com> wrote in message
> news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
>

No comments:

Post a Comment