为什么如果我们在运行存储过程时使用sql服务器名称超时 [英] why if we use sql server name timeout at running stored procedure

查看:69
本文介绍了为什么如果我们在运行存储过程时使用sql服务器名称超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了如下的连接字符串

Hi,

I have using connection string as below

<add name="ConnectionString" connectionstring="User Id = sa; Password = sa; Database = CineVistaDB; Data Source=VEERESH\SQLEXPRESS;" />



如果我使用这样的数据源名称,则在运行任何存储过程时都会发生超时异常.此外,我知道该存储过程具有单个T-Sql语句,并且可以在查询运行窗口中快速运行.请回复

如何解决此问题以及如何使用PC的IP地址更改数据源名称,例如Data Source = 192.168.0.68



If i use Data Source name like this,i''m getting timeout exception while running any Stored procedure.Addition, i know that stored procedure having single T-Sql statement and runs fastly at query runnung window.Please reply to

How to solve this and to change Data source name with ip address of PC,something like Data Source=192.168.0.68

推荐答案

增加SQL连接和服务器超时的值; SQL命令

对于Web.Config中的连接,
Increase value for Timeout of your SQL Connection & SQL Command

For Connection in Web.Config,
<add key="ConnectionString" value="server=(local); uid=sa; password=sa; database=master;Connection Timeout=30" />


对于Command,


For Command,

public void CreateSqlCommand()
{
   SqlCommand cmd = new SqlCommand();
   cmd.CommandTimeout = 15;
   cmd.CommandType = CommandType.Text;
}


&也请看以下页面.
问题排查:超时已过期 [ DBA超时快速指南 [ ^ ]


& also take a look at the following page.
Troubleshooting: Timeout expired[^]

Free attachment
DBA’s Quick Guide to Timeouts[^]


您必须使用此代码来避免出现此问题

使用系统< pre lang ="c#"></pre> .Data.SqlClient;


SqlCommand GstCommand =新的SqlCommand();
GstCommand.CommandTimeout = 60;


添加此代码后,您将不会遇到此问题.
you have to use this code to avoid this problem

using System<pre lang="c#"></pre>.Data.SqlClient;


SqlCommand GstCommand = new SqlCommand();
GstCommand.CommandTimeout = 60;


after adding this code you will not face this problem.


如果您的专家未使用上述解决方案删除,则
您只需验证您的查询(从存储过程中)执行时间即可.
并优化您的查询.
因为您的查询比服务器响应时间花费更多的时间.
这样就会发生超时错误.
If your excep not remove using above solution,then
you just verify your query(from stored procedure)execution time.
and optimize your query.
becoz your query take more time than server resp time.
that way timeout error excep occured.


这篇关于为什么如果我们在运行存储过程时使用sql服务器名称超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆