Professional Web Applications Themes

Programmatically accessing SQL server name - Microsoft SQL / MS SQL Server

Hi Is there any way to read the server name an SQL script is running on? I've written a "generic" backup/restore stored procedure to create/restore snapshots of certain databases, but I want to restrict certain functions in the stored proc based on which server it's running on. (i.e. restoring a snapshot should only be possible on our test environment, whereas creating a snapshot is possible both in live, UAT and test). Thanks Alex...

  1. #1

    Default Programmatically accessing SQL server name

    Hi

    Is there any way to read the server name an SQL script is running on? I've
    written a "generic" backup/restore stored procedure to create/restore
    snapshots of certain databases, but I want to restrict certain functions in
    the stored proc based on which server it's running on. (i.e. restoring a
    snapshot should only be possible on our test environment, whereas creating a
    snapshot is possible both in live, UAT and test).

    Thanks
    Alex


    Alex Guest

  2. #2

    Default Re: Programmatically accessing SQL server name

    Alex,

    SELECT SERVERNAME
    or
    SELECT SERVERPROPERTY('servername')

    --
    Dinesh.
    SQL Server FAQ at
    http://www.tkdinesh.com

    "Alex" <com> wrote in message
    news:phx.gbl... 
    in 



    Dinesh.T.K Guest

  3. #3

    Default Re: Programmatically accessing SQL server name

    The two easiest ways are:

    1) select SERVERNAME
    2) select SERVERPROPERTY ( 'ServerName' )



    --
    ----------------------------------------------------
    The views expressed here are my own
    and not of my employer.
    ----------------------------------------------------
    "Alex" <com> wrote in message
    news:phx.gbl... 
    in 



    Kevin Guest

  4. #4

    Default Re: Programmatically accessing SQL server name

    D'oh!!! I should have realised it was so simple!

    Thanks.
    Alex


    "Dinesh.T.K" <mail.tkdinesh.com> wrote in message
    news:phx.gbl... [/ref]
    I've 
    > in [/ref]
    creating 
    >
    >[/ref]


    Alex Guest

  5. #5

    Default Re: Programmatically accessing SQL server name

    I need to get this value from inside a dts package via
    VbScript. How this could be done?
    Thanks in advance.
     [/ref]
    is running on? I've [/ref]
    create/restore [/ref]
    certain functions [/ref]
    (i.e. restoring a [/ref]
    environment, whereas creating 
    >
    >
    >.
    >[/ref]
    Ray Guest

  6. #6

    Default Re: Programmatically accessing SQL server name

    Ray,

    Set a global variable for servername.Have a sql task populate that.Then call
    the global variable from the vbscript.

    --
    Dinesh.
    SQL Server FAQ at
    http://www.tkdinesh.com

    "Ray" <com> wrote in message
    news:00f501c34d5b$0a5a5240$gbl... [/ref]
    > is running on? I've [/ref]
    > create/restore [/ref]
    > certain functions [/ref]
    > (i.e. restoring a [/ref]
    > environment, whereas creating 
    > >
    > >
    > >.
    > >[/ref][/ref]


    Dinesh.T.K Guest

Similar Threads

  1. accessing SO at server side
    By avanthika in forum Macromedia Flash Flashcom
    Replies: 5
    Last Post: April 13th, 09:25 PM
  2. Accessing my new MSSQL server
    By Keira* in forum Coldfusion Database Access
    Replies: 1
    Last Post: February 13th, 05:53 PM
  3. Replies: 0
    Last Post: June 14th, 02:38 PM
  4. Accessing UserControls programmatically
    By Janaka in forum ASP.NET Building Controls
    Replies: 3
    Last Post: October 13th, 12:42 PM
  5. Error Accessing webservice programmatically over HTTPS.
    By sathyamurthy in forum ASP.NET Web Services
    Replies: 0
    Last Post: July 23rd, 06:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139