PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > T-SQL
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
T-SQL

Réponse
 
LinkBack Outils de la discussion
Vieux 02/10/2008, 16h44   #1
ventalinks@nospammers.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut T-SQL

Hello,

I need to write a stored procedure that has two different user
connections to two different databases. Both db's are on the same one
server. Is this possible to create using Transact-SQL commands in a
stored procedure?

Thanks :-)
  Réponse avec citation
Vieux 02/10/2008, 16h51   #2
Roy Harvey (SQL Server MVP)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

On Thu, 02 Oct 2008 10:44:09 -0400, ventalinks@nospammers.com wrote:

>I need to write a stored procedure that has two different user
>connections to two different databases. Both db's are on the same one
>server. Is this possible to create using Transact-SQL commands in a
>stored procedure?


A stored procedure runs on one connection, but it can reference
multiple databases on the same instance of SQL Server. If you
describe what you actually need to do someone may be able to suggest
an approach.

Roy Harvey
Beacon Falls, CT
  Réponse avec citation
Vieux 02/10/2008, 17h04   #3
ventalinks@nospammers.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

Roy Harvey (SQL Server MVP) wrote:
> A stored procedure runs on one connection, but it can reference
> multiple databases on the same instance of SQL Server. If you
> describe what you actually need to do someone may be able to suggest
> an approach.


Thans for your reply. I wished to creat a report. Some data of the
report is confidential data. It is in another database requiring
different username and password. I am given all necessary usernames and
passwords. I would want to write the report that will combine these
data and regular data. Is this possibility?



> Roy Harvey
> Beacon Falls, CT

  Réponse avec citation
Vieux 02/10/2008, 17h05   #4
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

Since both databases are on the same server, you can reference both in a
single query (assuming user has permissions to both, etc.):

SELECT <columns>
FROM Database1.dbo.TableA AS A
JOIN Database2.dbo.TableB AS B
ON A.keycolumn = B.keycolumn;

Note that each table is prefixed with database and schema name.

--
Plamen Ratchev
http://www.SQLStudio.com
  Réponse avec citation
Vieux 02/10/2008, 17h43   #5
ventalinks@nospammers.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

Plamen Ratchev wrote:
> Since both databases are on the same server, you can reference both in a
> single query (assuming user has permissions to both, etc.):
>
> SELECT <columns>
> FROM Database1.dbo.TableA AS A
> JOIN Database2.dbo.TableB AS B
> ON A.keycolumn = B.keycolumn;
>
> Note that each table is prefixed with database and schema name.



Hello,

There are two different usernames and one has not access to the other
database. I am getting this error. I think this is do to access
privilige limitation:


The server principal "x" is not able to access the database "y" under
the current security context.


  Réponse avec citation
Vieux 02/10/2008, 17h51   #6
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

One way would be to create a linked server to the confidential database
using the user/pwd provided, then in a query you can reference the
linked server:

SELECT <columns>
FROM Database1.dbo.TableA AS A
JOIN LinkedServer.Database2.dbo.TableB AS B
ON A.keycolumn = B.keycolumn;

More details on linked servers and
sp_addlinkedserver/sp_addlinkedsrvlogin to create linked server and
login mapping:
http://msdn.microsoft.com/en-us/library/ms188279.aspx
http://msdn.microsoft.com/en-us/library/ms190479.aspx
http://msdn.microsoft.com/en-us/library/ms189811.aspx

Also, you can use context switching to gain access to the confidential
table via a different user:
http://msdn.microsoft.com/en-us/libr...6(SQL.90).aspx
http://articles.techrepublic.com.com...1-6158511.html


--
Plamen Ratchev
http://www.SQLStudio.com
  Réponse avec citation
Vieux 02/10/2008, 18h10   #7
ventalinks@nospammers.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

Plamen Ratchev wrote:
> One way would be to create a linked server to the confidential database
> using the user/pwd provided, then in a query you can reference the
> linked server:



Thanks for all of those links. I will research them and see if they
in my case.
  Réponse avec citation
Vieux 02/10/2008, 23h51   #8
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: T-SQL

(ventalinks@nospammers.com) writes:
> Plamen Ratchev wrote:
>> Since both databases are on the same server, you can reference both in a
>> single query (assuming user has permissions to both, etc.):
>>
>> SELECT <columns>
>> FROM Database1.dbo.TableA AS A
>> JOIN Database2.dbo.TableB AS B
>> ON A.keycolumn = B.keycolumn;
>>
>> Note that each table is prefixed with database and schema name.

>
>
> Hello,
>
> There are two different usernames and one has not access to the other
> database. I am getting this error. I think this is do to access
> privilige limitation:
>
>
> The server principal "x" is not able to access the database "y" under
> the current security context.


Before you do anything else, you should speak with your DBA. Maybe this
is just a case of malconfiguration. May the login x should be a user in
y as well. In that case, what Plamen suggested will work.

If the configuration is correct, you will need to set up a few things.
Or maybe rather someone with the powers-to-be will have to. There is a
longer article on my web site that discusses permissions in general,
including cross-database access: http://www.sommarskog.se/grantperm.html
that should get you started.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15675 seconds with 16 queries