RATE THIS ANSWER
+1
Click to Vote:
1
0
Last Answered:
May 17 2008 7:57 AM GMT
by Mrdenny
You shouldn't need to specify the database or the owner. Have them setup the default database of the new account to be your database (dbdeckard). Then use the sp_changeobjectowner procedure to change the owner of all your table objects from acct567x to dbo (database owner). That way the other account will be able to automatically find the tables (as will your read/write account). When you query for an object in SQL (in this case a table) SQL Server first checks for tables with your name as the owner, then if it doesn't find a table it checks to see if the table is owned by the dbo user.
You can use a cursor to change all your tables at once. There is no risk of data loss by doing this.
declare @t sysname
declare cur CURSOR for select name
from sysobjects
where uid = USER_ID('acct567x')
open cur
fetch next from cur into @t
while @@Fetch_Status = 0
BEGIN
set @t = 'acct567x.' + @t
exec sp_changeobjectowner @objname=@t, @newowner='dbo'
fetch next from cur into @t
END
close cur
deallocate cur
Now to avoid this problem in the future when you create objects you will need to specify the owner name of the object when you create it. For example
CREATE TABLE dbo.NewTable
(Column1 INT)
If you don't do this you'll have to change the owner of the table after you create it using the sp_changeobjectowner procedure.
Now to deal with your SQL Injection problem you need to get away from embedded T/SQL statements and start using stored procedures with input parameters. You can read up on this on this blog posting
Avoiding SQL Injection Attacks. By using this technique you should be able to avoid the SQL Injection problems.
You can read up on stored procedures
here which is part of the Back To Basics series
here and
here.
When switching out to stored procedures don't forget to grant your account rights to execute the stored procedure.
GRANT EXEC ON ProcedureName to Username