Sql Synonyms between 2 db's

Discussion in 'Databases' started by Froggy3k, Apr 28, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. First post here and looking forward to a good relationship with DiscountAsp. I've just uploaded my new site and I use 2 databases. One of my Sprocs utilizes a synonym to pull 2 fields from a table in DB #2. However I can't get it to work due to permissions. I'm using SQL 2008. Do I have to use the same password for both db's? (right now they are different).
    I've searched the forum and haven't seen anything about synonym's.
    Thanks in advance!
    Chris
     
  2. I'm a little confused on exactly what you are trying to do. So you have a SQL statement setup as a synonym, that statement is suppose to query another database? What's the error message?
     
  3. Thx Raymond for the response. When I try to setup a synonym in the production environment I get an error that I don't have the permissions to attach to the other db. I'll have to run it again and get the 'exact' error message.
    I have a single site. 2 db's (membership/app db and forum db). Sproc queries multiple tables in db1 but also pulls 2 fields from one table in db2. Originally I was thinking using a linked server command but that didn't work on my development pc. On my development machine using synonyms was the only was I could get it to work (inside the app_data folder). Maybe in a production environment I can just query each db in the sproc using [dbo].[tableName].[fieldName] but haven't tested that theory yet. I use a lot of joins (not really a lot but about 5) in the sproc. Disclaimer: I'm fairly new to sql statements so I may be missing something obvious.
    Many thanks!
    Chris
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    You'll need to assign permission of the SQL login (you can either create a new SQL Login or assign one of the primary user) to both database.

    You can query the DB using dbname.dbo.tablename
     
  5. Awesome! Thanks Bruce! I just remembered that's how I originally tried to do it but it wouldn't let me in VS for some reason. It'll come back to me.
    Thx!!!
    Chris
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page