locked
global SQL function RRS feed

  • Question

  • User1266736465 posted

    Hi Guys, Is there a way to create a global function with full permission to be used with all database in the sql server?

    Explain:

    I have couple of functions that I use with all my databases and instead of creating the function in all databases, I would create it in the master database instead and use the function with all other database created in the server with fully permission

    For Instance:
    Function GetPersonAge(dob datatime)  - Returns the accurate age of the person, what I mean by accurate is that is the person is not within the birthday month and day or passed the birthday month then age is not real.

    I tried the creating the function in the master database, but when I want to use it in one of databases created I get an error message no permission to access GetPersonAge()

    SELECT master.dbo.GetPersonAge('03/05/1945')

    So my question is, Is there a way to make the function global like one out of the box in SQL and just use it, or I always have to set permission to the function in the master database to the user or the other database?

    Thanks

    Thursday, April 30, 2020 5:21 PM

Answers

  • User2053451246 posted

    First off, this would only be possible on a server under your control, as a web application would not be able to access the master db in a shared hosting environment.

    I don't recommend it, but if it's your server, add the same user account to the master db that is accessing your application db, maybe?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 1, 2020 1:15 AM

All replies

  • User2053451246 posted

    First off, this would only be possible on a server under your control, as a web application would not be able to access the master db in a shared hosting environment.

    I don't recommend it, but if it's your server, add the same user account to the master db that is accessing your application db, maybe?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 1, 2020 1:15 AM
  • User1266736465 posted

    Thank you ryanbesko for your reply, I was 90% certain that this was possible unless you have full control of sql server, I thought that with the newest version of SQL server this could be possible or maybe there was a way to get away with it.

    Thanks 

    Monday, May 25, 2020 2:10 PM