如题,sql server 能不能针多不同的数据库单独设置时区呢?
有的话,请说明设置方法?
没有的话,请说明其他解决方法。

解决方案 »

  1.   


    难道只能在每个使用getdate的地方 dateadd(hour,xx,getdate())替换?
      

  2.   

    ---转的  取得数据库的时间,并且用此时间设置本机的时间
    这个自觉写得很不错,供参考:   
        
              Private   Sub   Button1_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button1.Click   
                      '取服务器时间   
                      Dim   cm   As   SqlClient.SqlCommand   
                      cm   =   New   SqlClient.SqlCommand("SELECT   GETDATE()",   Me.SqlConnection1)   
                      Me.SqlConnection1.Open()   
                      Dim   NowTime   As   String   =   cm.ExecuteScalar.ToString   
                      Me.SqlConnection1.Close()   
                      '取日期和时间   
                      Dim   arg   As   String   =   "{0}   {1}"   
                      Dim   argDate   As   String   =   String.Format(arg,   "Date",   CType(NowTime,   Date).ToShortDateString)   
                      Dim   argTime   As   String   =   String.Format(arg,   "Time",   CType(NowTime,   Date).ToLongTimeString)   
                      '以下设定本机日期和时间   
                      Dim   sw   As   System.IO.StreamWriter   
                      Dim   p   As   System.Diagnostics.Process   =   New   System.Diagnostics.Process   
                      Dim   psI   As   New   System.Diagnostics.ProcessStartInfo("cmd")   
                      psI.UseShellExecute   =   False   
                      psI.RedirectStandardInput   =   True   
                      psI.CreateNoWindow   =   True   
                      p.StartInfo   =   psI   
        
                      p.Start()   
                      sw   =   p.StandardInput   
                      sw.WriteLine(argDate)   
                      sw.WriteLine(argTime)   
                      sw.Close()   
              End   Sub
      

  3.   

    fredrickhu, 这个想法是好的,但不能用于我的应用。不可能使用服务器的时区设置来定义本地,这没有任何意义。
    只想服务器中存储和运算都按照 我预设的时区进行。
    假设服务器在欧洲,GMT+1
    而现在,中国GMT+8 是12:20
    那如果现在操作,服务器的getdate()将会是5:20,
    但是想要数据直接为 12:20,所以看来只能dateadd(,,)函数了。
      

  4.   

    一个机器上可以安装多个MSSQL的实例, 每个实例是可以单独设置时区的
    所以每不同的数据库放在不同的实例上就可以了
    现在才发现MSSQL搞个数据实例的作用了
      

  5.   

    服务器上加载那么多数据库,肯定不能为了通过系统时区就行设置的。每个实例单独设置时区,如何进行? Tomzzu?
    虽然不是想要最终结果,至少有进步啦。同理,每个实例下亦会加载多个数据库,可能单独为数据设置时区是不可能的了。