连接服务器时发生问题 [英] a problem occuring while connecting the server

查看:109
本文介绍了连接服务器时发生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在准备一个网站,并且在连接数据库时不得不遇到以下错误:

代码

导入System.Data.OleDb
导入System.Data.SqlClient

局部公共类_Default
继承System.Web.UI.Page

受保护的子Button1_Click(ByVal发送者作为对象,ByVal e作为EventArgs)处理btnAdd.Click
Dim str As String
昏暗ID为整数
id = getid()
str =插入AddGr值("& id&,"& txtName.Text&"'',"& txtAdd.Text&'',''"& txtCountry .Text&'',"& txtState.Text&'',"& txtCity.Text&"'',"&txtPho.Text&",, ''''& txtPhr.Text&'',''"& txtMob.Text&'')"
昏暗的cnn作为新的SqlConnection
昏暗的cmd作为新的SqlCommand
cnn.ConnectionString =数据源= C:\ aj \ aj \ App_Data \ Data.mdf"
cmd.CommandText = str
cmd.Connection = cnn
cnn.Open()
cmd.ExecuteNonQuery()
MsgBox(已添加记录")
cnn.Close()
txtId.Text ="
txtName.Text ="
txtAdd.Text ="
txtCountry.Text ="
txtState.Text ="
txtCity.Text ="
txtPho.Text ="
txtPhr.Text ="
txtMob.Text ="
结束子
函数getid()作为Integer
Dim retID为整数
昏暗的cnn作为新的SqlConnection

cnn.ConnectionString =数据源= C:\ aj \ aj \ App_Data \ Data.mdf"
昏暗的cmd作为新的SqlCommand(从addGr选择max(GrID)",cnn)
cnn.Open()
MsgBox(cnn.State)


如果IsDBNull(cmd.ExecuteScalar)然后
retID = 0
其他
retID = cmd.ExecuteScalar
如果结束

cnn.Close()
返回retID + 1
最终功能

错误

与服务器建立连接时发生错误.
连接到SQL Server 2005时,此失败可能是由于在默认设置下SQL Server不允许远程连接. (提供者:SQL网络接口,错误:26-查找指定的服务器/实例时出错)"

可能是什么问题以及与此相关的解决方案.


运行网页时出现此错误.

请做必要的操作



I was preparing a website and while connecting to the database i had to ancounter this error:

code

Imports System.Data.OleDb
Imports System.Data.SqlClient

Partial Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
Dim str As String
Dim id As Integer
id = getid()
str = "insert into AddGr values(" & id & ",''" & txtName.Text & "'',''" & txtAdd.Text & "'',''" & txtCountry.Text & "'',''" & txtState.Text & "'',''" & txtCity.Text & "'',''" & txtPho.Text & "'',''" & txtPhr.Text & "'',''" & txtMob.Text & "'')"
Dim cnn As New SqlConnection
Dim cmd As New SqlCommand
cnn.ConnectionString = "Data Source= C:\aj\aj\App_Data\Data.mdf"
cmd.CommandText = str
cmd.Connection = cnn
cnn.Open()
cmd.ExecuteNonQuery()
MsgBox("Record Added")
cnn.Close()
txtId.Text = ""
txtName.Text = ""
txtAdd.Text = ""
txtCountry.Text = ""
txtState.Text = ""
txtCity.Text = ""
txtPho.Text = ""
txtPhr.Text = ""
txtMob.Text = ""
End Sub
Function getid() As Integer
Dim retID As Integer
Dim cnn As New SqlConnection

cnn.ConnectionString = "Data Source=C:\aj\aj\App_Data\Data.mdf"
Dim cmd As New SqlCommand("Select max(GrID) from addGr", cnn)
cnn.Open()
MsgBox(cnn.State)


If IsDBNull(cmd.ExecuteScalar) Then
retID = 0
Else
retID = cmd.ExecuteScalar
End If

cnn.Close()
Return retID + 1
End Function

Error

"An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

what could be the problem and the solution regarding to this.


I got this error while running my webpage.

please do needful

推荐答案

按照 ^ ]


您可以使用这些束进行故障排除

解决SQL连接问题的步骤 [ ^ ]
SQL Server 2005连接性问题疑难解答-第一部分 [对SQL Server 2005中的连接问题进行故障排除-第二部分 [ ^ ]
对SQL Server 2005中的连接问题进行故障排除-第III部分 [ ^ ]

顺便说一句,我也给了你这堆,以防将来出错.
You can troubleshoot with these bunch

Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]

BTW I gave you this bunch also for future errors.


这篇关于连接服务器时发生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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