silverlight连接2个数据库

liuliulp 2014-04-02 11:12:26
我在一个silverlight项目中需要连接2个数据库,使用了WCF服务,Web.config文件连接数据库字符串如下:
<connectionStrings>
<add name="SqlSource" connectionString="Data Source=(Local);Initial Catalog=bLineAndonSysDB;Persist Security Info=True;User ID=sa;Password=123;Max Pool Size=512" providerName="System.Data.SqlClient"/>
<add name="Sql" connectionString="Data Source=(Local);Initial Catalog=bLineAndonDataRecord;Persist Security Info=True;User ID=sa;Password=123;Max Pool Size=512" providerName="System.Data.SqlClient"/>
</connectionStrings>

在服务中设置如下:
private string connectionString = ConfigurationManager.ConnectionStrings["SqlSource"].ConnectionString;
private string conString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
当在VS中调试的时候,没有问题,调用的2个数据库都能正常访问,然而在部署到IIS上后,其中有一个数据库不能正常打开,求大神指导 谢谢。。。。。


...全文
238 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bonjour-你好 2014-04-04
  • 打赏
  • 举报
回复
引用 16 楼 liuliulp 的回复:
问题基本找到了,查询数据时,客户端需要传递当时时间给wcf服务,我用的是System.DateTime.Now.ToString()方法,当在服务端把SQL语句写成固定语句时客户端是有结果的,不过当将客户端当前时间传递给服务端时,客户端有时有数据,有时就没有数据,这个问题暂时还无法解决。。。。
是不是时间转为字符串的格式问题啊?一般ToString("yyyy-MM-dd HH:mm:ss")
liuliulp 2014-04-04
  • 打赏
  • 举报
回复
引用 14 楼 KumaPower 的回复:
[quote=引用 13 楼 liuliulp 的回复:] [quote=引用 12 楼 KumaPower 的回复:] 试试把第二个的代码,直接返回 null ,再看看客户端那边能不能弹出信息框,先排除数据库连接。
第二段代码直接返回null时,客户端那边能弹出对话框,是我连接数据库有问题?[/quote] 主要是你调试的时候不会出现问题,所以我也不清楚是连接出问题还是执行的时候出问题,对于在非调试阶段获取出错信息,可以尝试加上try...catch语句,在catch中把捕获到的错误写到一个文件中,方便看出错误,如配置log4net。[/quote] 问题基本找到了,查询数据时,客户端需要传递当时时间给wcf服务,我用的是System.DateTime.Now.ToString()方法,当在服务端把SQL语句写成固定语句时客户端是有结果的,不过当将客户端当前时间传递给服务端时,客户端有时有数据,有时就没有数据,这个问题暂时还无法解决。。。。
liuliulp 2014-04-04
  • 打赏
  • 举报
回复
引用 19 楼 KumaPower 的回复:
[quote=引用 18 楼 liuliulp 的回复:] [quote=引用 17 楼 KumaPower 的回复:] [quote=引用 16 楼 liuliulp 的回复:] 问题基本找到了,查询数据时,客户端需要传递当时时间给wcf服务,我用的是System.DateTime.Now.ToString()方法,当在服务端把SQL语句写成固定语句时客户端是有结果的,不过当将客户端当前时间传递给服务端时,客户端有时有数据,有时就没有数据,这个问题暂时还无法解决。。。。
是不是时间转为字符串的格式问题啊?一般ToString("yyyy-MM-dd HH:mm:ss")[/quote] 额 好像还是不对,用360浏览器行,用IE却不行。。。。。。。。[/quote] 不是吧,返回结果还分浏览器?应该不会这样的啊~[/quote] 都搞不懂了、太诡异了。。。。。。。。
Bonjour-你好 2014-04-04
  • 打赏
  • 举报
回复
引用 18 楼 liuliulp 的回复:
[quote=引用 17 楼 KumaPower 的回复:] [quote=引用 16 楼 liuliulp 的回复:] 问题基本找到了,查询数据时,客户端需要传递当时时间给wcf服务,我用的是System.DateTime.Now.ToString()方法,当在服务端把SQL语句写成固定语句时客户端是有结果的,不过当将客户端当前时间传递给服务端时,客户端有时有数据,有时就没有数据,这个问题暂时还无法解决。。。。
是不是时间转为字符串的格式问题啊?一般ToString("yyyy-MM-dd HH:mm:ss")[/quote] 额 好像还是不对,用360浏览器行,用IE却不行。。。。。。。。[/quote] 不是吧,返回结果还分浏览器?应该不会这样的啊~
liuliulp 2014-04-04
  • 打赏
  • 举报
回复
引用 17 楼 KumaPower 的回复:
[quote=引用 16 楼 liuliulp 的回复:] 问题基本找到了,查询数据时,客户端需要传递当时时间给wcf服务,我用的是System.DateTime.Now.ToString()方法,当在服务端把SQL语句写成固定语句时客户端是有结果的,不过当将客户端当前时间传递给服务端时,客户端有时有数据,有时就没有数据,这个问题暂时还无法解决。。。。
是不是时间转为字符串的格式问题啊?一般ToString("yyyy-MM-dd HH:mm:ss")[/quote] 额 好像还是不对,用360浏览器行,用IE却不行。。。。。。。。
Bonjour-你好 2014-04-03
  • 打赏
  • 举报
回复
引用 13 楼 liuliulp 的回复:
[quote=引用 12 楼 KumaPower 的回复:] 试试把第二个的代码,直接返回 null ,再看看客户端那边能不能弹出信息框,先排除数据库连接。
第二段代码直接返回null时,客户端那边能弹出对话框,是我连接数据库有问题?[/quote] 主要是你调试的时候不会出现问题,所以我也不清楚是连接出问题还是执行的时候出问题,对于在非调试阶段获取出错信息,可以尝试加上try...catch语句,在catch中把捕获到的错误写到一个文件中,方便看出错误,如配置log4net。
liuliulp 2014-04-03
  • 打赏
  • 举报
回复
引用 12 楼 KumaPower 的回复:
试试把第二个的代码,直接返回 null ,再看看客户端那边能不能弹出信息框,先排除数据库连接。
第二段代码直接返回null时,客户端那边能弹出对话框,是我连接数据库有问题?
Bonjour-你好 2014-04-03
  • 打赏
  • 举报
回复
试试把第二个的代码,直接返回 null ,再看看客户端那边能不能弹出信息框,先排除数据库连接。
liuliulp 2014-04-03
  • 打赏
  • 举报
回复
引用 10 楼 KumaPower 的回复:
[quote=引用 9 楼 liuliulp 的回复:] 打开浏览器是能够看到wcf服务信息的,我这个程序里面有2个访问数据库的操作,其中一个都能正常访问,另一个就没有响应,我在VS中调试时都没有问题,2个数据库都能正常访问
嗯,主要是我想确定第二那个wcf访问时,浏览器信息是返回200代码还是其他404等错误的代码,因为你上面说没有进入client_readCurrentAlarmInforCompleted中,所以我就猜会不会第二个wcf没有被访问到。如果你数据库是用SQL Server的,还可以尝试用SQL Server Profiler来监测一下数据库的操作情况。[/quote]
引用 10 楼 KumaPower 的回复:
[quote=引用 9 楼 liuliulp 的回复:] 打开浏览器是能够看到wcf服务信息的,我这个程序里面有2个访问数据库的操作,其中一个都能正常访问,另一个就没有响应,我在VS中调试时都没有问题,2个数据库都能正常访问
嗯,主要是我想确定第二那个wcf访问时,浏览器信息是返回200代码还是其他404等错误的代码,因为你上面说没有进入client_readCurrentAlarmInforCompleted中,所以我就猜会不会第二个wcf没有被访问到。如果你数据库是用SQL Server的,还可以尝试用SQL Server Profiler来监测一下数据库的操作情况。[/quote] 我只建了一个WCF服务,在该服务中有2契约函数,如下: public List<MonitorInfor> readMonitorInfor() { string strsql; strsql = "select StationID,StationName,statusColour,statusInfo,ProductNameAndSpec,ProductBatchNum,TheDownTime,AccumulatedDownTime,ScheduledProduction,ActualProduction from CurrentViewInfo"; SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = new SqlCommand(strsql, conn); SqlDataReader sdr = cmd.ExecuteReader(); List<MonitorInfor> list = new List<MonitorInfor>(); list.Clear(); while (sdr.Read()) { MonitorInfor myMonitorInforValue = new MonitorInfor(); myMonitorInforValue.stationID = sdr["StationID"].ToString(); myMonitorInforValue.stationName = sdr["StationName"].ToString(); myMonitorInforValue.statusColour = sdr["statusColour"].ToString(); myMonitorInforValue.statusInfo = sdr["statusInfo"].ToString(); myMonitorInforValue.productNameAndSpec = sdr["ProductNameAndSpec"].ToString(); myMonitorInforValue.productBatchNum = sdr["ProductBatchNum"].ToString(); // DateTime myDownTime = DateTime.Parse("00:00:00"); // myMonitorInforValue.theDownTime = myDownTime.AddSeconds(Convert.ToDouble(sdr["TheDownTime"].ToString())).ToString().Substring(10); // myMonitorInforValue.theDownTime = sdr["TheDownTime"].ToString(); // DateTime myAccumulatedDownTime = new DateTime( Convert.ToInt64( sdr["TheDownTime"].ToString())); // DateTime myAccumulatedDownTime = DateTime.Parse("00:00:00"); myMonitorInforValue.theDownTime = sdr["TheDownTime"].ToString(); myMonitorInforValue.accumulatedDownTime = sdr["AccumulatedDownTime"].ToString(); myMonitorInforValue.scheduledProduction = sdr["ScheduledProduction"].ToString(); myMonitorInforValue.actualProduction = sdr["ActualProduction"].ToString(); list.Add(myMonitorInforValue); } conn.Close(); return list; } [OperationContract] public List<AlarmInfor> readCurrentAlarmInfor() { string strsql; strsql = "select top 1 StationIndex,StateLevel,StartTime from StateChangeRecord where (StateLevel ='3' or StateLevel = '2') and StartTime between '" + dateStr.Remove(10) + " 00:00:00.000" + "' and '" + dateStr.Remove(10) + " 23:59:59.000'" +" and EndTime is null" + " order by StartTime desc"; SqlConnection conn = new SqlConnection(conString); conn.Open(); SqlCommand cmd = new SqlCommand(strsql, conn); SqlDataReader sdr = cmd.ExecuteReader(); List<AlarmInfor> list = new List<AlarmInfor>(); list.Clear(); while (sdr.Read()) { AlarmInfor myAlarmInfor = new AlarmInfor(); myAlarmInfor.stationIndex = sdr["StationIndex"].ToString(); myAlarmInfor.stateLeval = sdr["StateLevel"].ToString(); myAlarmInfor.startTime = sdr["StartTime"].ToString(); // myAlarmInfor.endTime = sdr["EndTime"].ToString(); list.Add(myAlarmInfor); } conn.Close(); return list; } 调用第一个没有问题,第二个不知调用没有,因为在VS中2个都是没有问题的,
Bonjour-你好 2014-04-03
  • 打赏
  • 举报
回复
引用 9 楼 liuliulp 的回复:
打开浏览器是能够看到wcf服务信息的,我这个程序里面有2个访问数据库的操作,其中一个都能正常访问,另一个就没有响应,我在VS中调试时都没有问题,2个数据库都能正常访问
嗯,主要是我想确定第二那个wcf访问时,浏览器信息是返回200代码还是其他404等错误的代码,因为你上面说没有进入client_readCurrentAlarmInforCompleted中,所以我就猜会不会第二个wcf没有被访问到。如果你数据库是用SQL Server的,还可以尝试用SQL Server Profiler来监测一下数据库的操作情况。
liuliulp 2014-04-03
  • 打赏
  • 举报
回复
引用 8 楼 KumaPower 的回复:
[quote=引用 4 楼 liuliulp 的回复:] [quote=引用 3 楼 KumaPower 的回复:] 不能打开有没有什么错误提示啊?
我是估计不能打开, private void readCurrentAlarmInfor() { EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/AndonInforService.svc")); AndonInforServiceClient client = new AndonInforServiceClient(new BasicHttpBinding(), address); client.readCurrentAlarmInforCompleted += client_readCurrentAlarmInforCompleted; MessageBox.Show("1"); client.readCurrentAlarmInforAsync(); } private void client_readCurrentAlarmInforCompleted(object sender, readCurrentAlarmInforCompletedEventArgs e) { MessageBox.Show(e.Result.Count.ToString()+"aa"); } 能运行到MessageBox.Show("1");那行,MessageBox.Show(e.Result.Count.ToString()+"aa");运行不到,不能弹出对话框[/quote] 如madaming所说,很有可能是wcf本身没有被访问到,你打开浏览器的调试器至少能看到访问wcf的地址是否正确的信息。[/quote] 打开浏览器是能够看到wcf服务信息的,我这个程序里面有2个访问数据库的操作,其中一个都能正常访问,另一个就没有响应,我在VS中调试时都没有问题,2个数据库都能正常访问
海涵德 2014-04-03
  • 打赏
  • 举报
回复
不是数据库问题,是wcf相对地址问题。 private ServiceReference1.Service1Client wcf = new ServiceReference1.Service1Client(); use_wcf(ref wcf, @"../Services/Service1.svc"); //////////////////////////////////////////////////////// @“../Services/Service1.svc”就是你的wcf所在位置
Bonjour-你好 2014-04-03
  • 打赏
  • 举报
回复
引用 4 楼 liuliulp 的回复:
[quote=引用 3 楼 KumaPower 的回复:] 不能打开有没有什么错误提示啊?
我是估计不能打开, private void readCurrentAlarmInfor() { EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/AndonInforService.svc")); AndonInforServiceClient client = new AndonInforServiceClient(new BasicHttpBinding(), address); client.readCurrentAlarmInforCompleted += client_readCurrentAlarmInforCompleted; MessageBox.Show("1"); client.readCurrentAlarmInforAsync(); } private void client_readCurrentAlarmInforCompleted(object sender, readCurrentAlarmInforCompletedEventArgs e) { MessageBox.Show(e.Result.Count.ToString()+"aa"); } 能运行到MessageBox.Show("1");那行,MessageBox.Show(e.Result.Count.ToString()+"aa");运行不到,不能弹出对话框[/quote] 如madaming所说,很有可能是wcf本身没有被访问到,你打开浏览器的调试器至少能看到访问wcf的地址是否正确的信息。
liuliulp 2014-04-03
  • 打赏
  • 举报
回复
引用 6 楼 madaming 的回复:
还是那个老问题,wcf相对地址问题。
  #region - 引用WCF
        public static EndpointAddress getEndpointAddress(string relative_uri)
        {
            return new EndpointAddress(new Uri(Application.Current.Host.Source, relative_uri));
        }
        public static void use_wcf(ref  ServiceReference1.Service1Client   wcf_instance, string end_point_address)
        {
            EndpointAddress _end_point_address = getEndpointAddress(end_point_address);
            //调用wcf超时的解决办法
#if (TRACE)
            wcf_instance.Endpoint.Binding.OpenTimeout = new TimeSpan(0, 18, 0);
            wcf_instance.Endpoint.Binding.CloseTimeout = new TimeSpan(0, 18, 0);
            wcf_instance.Endpoint.Binding.SendTimeout = new TimeSpan(1, 18, 0);
            wcf_instance.Endpoint.Binding.ReceiveTimeout = new TimeSpan(1, 18, 0);
#else
        wcf_instance.Endpoint.Binding.OpenTimeout = new TimeSpan(0, 1, 0);
        wcf_instance.Endpoint.Binding.CloseTimeout = new TimeSpan(0, 1, 0);
        wcf_instance.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
        wcf_instance.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
#endif
            wcf_instance.Endpoint.Address = _end_point_address;
        }
        #endregion

    private ServiceReference1.Service1Client wcf = new ServiceReference1.Service1Client();
    use_wcf(ref wcf, @"../Services/Service1.svc");
没有看懂,求指导。。。。。
Bonjour-你好 2014-04-02
  • 打赏
  • 举报
回复
不能打开有没有什么错误提示啊?
liuliulp 2014-04-02
  • 打赏
  • 举报
回复
引用 楼主 liuliulp 的回复:
我在一个silverlight项目中需要连接2个数据库,使用了WCF服务,Web.config文件连接数据库字符串如下:
<connectionStrings>
<add name="SqlSource" connectionString="Data Source=(Local);Initial Catalog=bLineAndonSysDB;Persist Security Info=True;User ID=sa;Password=123;Max Pool Size=512" providerName="System.Data.SqlClient"/>
<add name="Sql" connectionString="Data Source=(Local);Initial Catalog=bLineAndonDataRecord;Persist Security Info=True;User ID=sa;Password=123;Max Pool Size=512" providerName="System.Data.SqlClient"/>
</connectionStrings>

在服务中设置如下:
private string connectionString = ConfigurationManager.ConnectionStrings["SqlSource"].ConnectionString;
private string conString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
当在VS中调试的时候,没有问题,调用的2个数据库都能正常访问,然而在部署到IIS上后,其中有一个数据库不能正常打开,求大神指导 谢谢。。。。。


引用 1 楼 wwwxhb 的回复:
Data Source=(Local) 数据源位置不一样吧


数据库都是在本地的SQLServer上,如下图:
wwwxhb 2014-04-02
  • 打赏
  • 举报
回复
Data Source=(Local) 数据源位置不一样吧
海涵德 2014-04-02
  • 打赏
  • 举报
回复
还是那个老问题,wcf相对地址问题。
  #region - 引用WCF
        public static EndpointAddress getEndpointAddress(string relative_uri)
        {
            return new EndpointAddress(new Uri(Application.Current.Host.Source, relative_uri));
        }
        public static void use_wcf(ref  ServiceReference1.Service1Client   wcf_instance, string end_point_address)
        {
            EndpointAddress _end_point_address = getEndpointAddress(end_point_address);
            //调用wcf超时的解决办法
#if (TRACE)
            wcf_instance.Endpoint.Binding.OpenTimeout = new TimeSpan(0, 18, 0);
            wcf_instance.Endpoint.Binding.CloseTimeout = new TimeSpan(0, 18, 0);
            wcf_instance.Endpoint.Binding.SendTimeout = new TimeSpan(1, 18, 0);
            wcf_instance.Endpoint.Binding.ReceiveTimeout = new TimeSpan(1, 18, 0);
#else
        wcf_instance.Endpoint.Binding.OpenTimeout = new TimeSpan(0, 1, 0);
        wcf_instance.Endpoint.Binding.CloseTimeout = new TimeSpan(0, 1, 0);
        wcf_instance.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
        wcf_instance.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
#endif
            wcf_instance.Endpoint.Address = _end_point_address;
        }
        #endregion

    private ServiceReference1.Service1Client wcf = new ServiceReference1.Service1Client();
    use_wcf(ref wcf, @"../Services/Service1.svc");
海涵德 2014-04-02
  • 打赏
  • 举报
回复
你的问题不是数据库打不开的问题,是wcf没有响应的问题。 简单做一个wcf返回字符串的例子就知道了。
liuliulp 2014-04-02
  • 打赏
  • 举报
回复
引用 3 楼 KumaPower 的回复:
不能打开有没有什么错误提示啊?
我是估计不能打开, private void readCurrentAlarmInfor() { EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/AndonInforService.svc")); AndonInforServiceClient client = new AndonInforServiceClient(new BasicHttpBinding(), address); client.readCurrentAlarmInforCompleted += client_readCurrentAlarmInforCompleted; MessageBox.Show("1"); client.readCurrentAlarmInforAsync(); } private void client_readCurrentAlarmInforCompleted(object sender, readCurrentAlarmInforCompletedEventArgs e) { MessageBox.Show(e.Result.Count.ToString()+"aa"); } 能运行到MessageBox.Show("1");那行,MessageBox.Show(e.Result.Count.ToString()+"aa");运行不到,不能弹出对话框

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧