views:

362

answers:

2

I'm using "SQL SERVER PROJECT" in VS 2008 to create UDF in C# Then I'm using DEPLOY command to publish DLL into MS SQL server 2005

All works well except all created UDFs are owned by me (as user) But I wanted to keep dbo schema (eg: dbo.UDF_TEST - not jonny.UDF_TEST)

Any idea how to manage thar?

+1  A: 

deploy the UDF from an account that is sysadmin, or dbo on the database. You can build the dll and then manually deploy it by logging into management studio as dbo to the database and running these commands:

CREATE ASSEMBLY Geocode FROM

'C:\PATH\YourUDF.dll' WITH

PERMISSION_SET = SAFE

or

  1. From within Visual Studio in the solution explorer click on the UDF project (not the solution).
  2. Go to properties.
  3. Click on the database tab.
  4. You can change the connection string, and also change the assembly owner here.
Nick Kavadias
Thanks for reply.I'm forced to use AD and Windows auth.So I cannot easy log as dboI'd prefrer 2nd option you have mentioned.I've SQL Server project, then at its property I've entered "dbo" at assembly owner as adviced - unfortunatelly it didnt helpWhat I'm doing wrong?
Maciej
you need to be sysadmin on the database to be able to set objects to have dbo ownership
Nick Kavadias
Unfortunatelly I'm not sysadmin - I'm developer...
Maciej
+1  A: 

I've found another approach allowing do everything inside VS.

I've added to project SQL script named "postdeployscript.sql":

DECLARE @SQL NVARCHAR(200)

SET @SQL = 'alter schema dbo transfer ' + CURRENT_USER +'.[UDF_GET_AUDIT_VALUE]'

EXECUTE (@SQL)

GO

script is executed automaticcally by VS during depolyment process and changes schemas from current user to DBO.

Cons: you need to add each UDF/USP you are ceating manually

PS: Please note you can also use predeployscript.sql to execute some commmands before deployment

Maciej
You don't have to add them manually - you can use something like "SELECT name FROM sysobjects where xtype='FN'" and just iterate over that to apply the changes to every function in your database.
rwmnau