SQL连接错误 [英] SQL Connection Error

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

问题描述

我正在尝试连接到另一台计算机上的SQL服务器

。我可以在企业管理器中查看内容和

查询分析器。当我尝试从Web应用程序连接到这个

数据库时出现问题。显然我需要在SQL服务器上实际登录和

密码才能从Web应用程序进行连接。

总是如此,或者有办法解决这个问题。如果它意味着

任何东西,我使用Visual Studio .NET 2003并导入所有

相关(我相信如此)命名空间,以便工作。


连接字符串:


< add key =" SQLConnection" value =" Data Source = ServerName; Initial

Catalog = DatabaseName />

测试连接:


Private Sub Page_Load (ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

''将用户代码置于此处初始化页面

尝试


Dim objSQLConn As New

SqlClient.SqlConnection(ConfigurationSettings.AppS ettings(" SQLConnection"))

objSQLConn.Open()

如果objSQLConn.State = ConnectionState.Open那么

Label1.Text =" SQL连接已打开

否则

Label1.Text =SQL连接已关闭

结束如果


Catch sqlxcp作为SqlClient.SqlException

Label2.Text = sqlxcp.ToString

Label3.Text = sqlxcp.Message

Label4.Text = sqlxcp.Source

Label5.Text = sqlxcp.Number

最后

结束尝试


结束子

_______ _______________


我可以在VS .NET的数据集填充程序中查看数据,但是当我通过Web应用程序实际连接
时,我得到了一个过多的错误。任何

的建议?

解决方案

我想我应该提供错误:


用户''(null)''登录失败。原因:与可信任的

SQL Server连接无关。



18452


我可以使用我的Windows NT

帐户查看SQL服务器表和数据,但是当我尝试从Web应用程序连接时却没有。任何

建议?


你需要包含一个用户名和密码,除非你想添加

ASPNET帐户到SQL Server(我不推荐)。现在你是

告诉SQL使用可信连接(默认情况下,如果没有指定)。


您的连接字符串可能如下所示:

数据源=(LOCAL);初始目录= YourDataBase; uid = UserName; pwd =密码;

Clint Hill

H3O软件
http://www.h3osoftware.com

Sparky Arbuckle写道:< blockquote class =post_quotes>我正在尝试连接到建筑物中不同机器上的SQL服务器。我可以在企业管理器和查询分析器中查看内容。当我尝试从Web应用程序连接到此数据库时出现问题。显然,我需要SQL服务器上的实际登录和
密码才能从Web应用程序进行连接。
总是如此,或者有办法解决这个问题。如果它意味着什么,我使用Visual Studio .NET 2003并导入了所有相关(我相信如此)命名空间,以便工作。

连接字符串:

< add key =" SQLConnection" value =" Data Source = ServerName; Initial
Catalog = DatabaseName />

测试连接:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)处理MyBase.Load
''用户代码初始化页面
尝试

Dim objSQLConn As New
SqlClient.SqlConnection(ConfigurationSettings.AppS ettings(" SQLConnection"))
objSQLConn.Open()
如果objSQLConn.State = ConnectionState.Open那么
Label1.Text =" SQL连接是打开
否则
Label1.Text =" SQL连接已关闭
结束如果

Catch sqlxcp为SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Label3.Text = sqlxcp.Message
Label4.Text = sqlxcp.Source
Label5.Text = sqlxcp.Number
最后结束尝试

结束子
______________________

我可以在VS .NET的数据集填充中查看数据,但是当我走的时候
通过Web应用程序实际连接我得到了大量的错误。任何
建议?



感谢Clint的回复。


我正在运行这个应用程序我的inetpub文件夹,直到我能够将它b / b
上传到网络服务器。我想先测试一切。我尝试将

uid和pwd添加到我的连接字符串中,现在我收到错误:


用户''UserName''登录失败。


..Net SqlClient数据提供者


18456


在VS中右键单击适配器预览这个

连接的数据集我可以很好地查看,所以我知道我能够连接到这个

数据库。我的Windows身份验证是我用来通过企业管理器和查询分析器连接到

SQL服务器的。这完美无瑕地工作

。唯一的问题是当我尝试通过网络应用程序连接时。


这是否有意义还是我需要澄清更多?


I am trying to connect to a SQL server that is on a different machine
in the building. I can view the contents in Enterprise Manager and
Query Analyzer. The problems arise when I try to connect to this
database from a web application. Apparently I need an actual login and
password on the SQL server for connecting from a web application. Is
this always the case or are there ways around this. If it means
anything, I am using Visual Studio .NET 2003 and have imported all
relevant (I believe so) namespaces for this to work.

Connection string:

<add key="SQLConnection" value="Data Source=ServerName;Initial
Catalog=DatabaseName />
Testing connectivity:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Put user code to initialize the page here
Try

Dim objSQLConn As New
SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SQLConnection"))
objSQLConn.Open()
If objSQLConn.State = ConnectionState.Open Then
Label1.Text = "SQL Connection is open"
Else
Label1.Text = "SQL Connection is closed"
End If

Catch sqlxcp As SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Label3.Text = sqlxcp.Message
Label4.Text = sqlxcp.Source
Label5.Text = sqlxcp.Number
Finally
End Try

End Sub
______________________

I can view the data just fine in VS .NET''s dataset filler but when I go
to actually connect via web application I get a plethora of errors. Any
suggestions?

解决方案

I guess I should probably provide the errors:

Login failed for user ''(null)''. Reason: Not associated with a trusted
SQL Server connection.

..Net SqlClient Data Provider

18452

I can view the SQL server tables and data just fine using my Windows NT
account but not when I try to connect from a web application. Any
suggestions?


You do need to include a username and password unless you want to add
ASPNET account to SQL Server (not recommended by me). Right now you are
telling SQL to use a Trusted Connection (default if not specified).

your connection string might look like this:
data source=(LOCAL);initial catalog=YourDataBase;uid=UserName;pwd=Password;
Clint Hill
H3O Software
http://www.h3osoftware.com
Sparky Arbuckle wrote:

I am trying to connect to a SQL server that is on a different machine
in the building. I can view the contents in Enterprise Manager and
Query Analyzer. The problems arise when I try to connect to this
database from a web application. Apparently I need an actual login and
password on the SQL server for connecting from a web application. Is
this always the case or are there ways around this. If it means
anything, I am using Visual Studio .NET 2003 and have imported all
relevant (I believe so) namespaces for this to work.

Connection string:

<add key="SQLConnection" value="Data Source=ServerName;Initial
Catalog=DatabaseName />
Testing connectivity:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Put user code to initialize the page here
Try

Dim objSQLConn As New
SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SQLConnection"))
objSQLConn.Open()
If objSQLConn.State = ConnectionState.Open Then
Label1.Text = "SQL Connection is open"
Else
Label1.Text = "SQL Connection is closed"
End If

Catch sqlxcp As SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Label3.Text = sqlxcp.Message
Label4.Text = sqlxcp.Source
Label5.Text = sqlxcp.Number
Finally
End Try

End Sub
______________________

I can view the data just fine in VS .NET''s dataset filler but when I go
to actually connect via web application I get a plethora of errors. Any
suggestions?



Thanks for the reply Clint.

I am running this app from my inetpub folder until I am able to upload
it to a web server. I want to test everything first. I tried adding
uid and pwd to my connection string and now I am getting the error:

Login failed for user ''UserName''.

..Net SqlClient Data Provider

18456

In VS when I right-click the adapter to preview dataset for this
connection I can view just fine so I know I''m able to connect to this
database. My windows authentication is what I used to connect to the
SQL server via Enterprise manager and Query Analyzer. This works
flawlessly. The only problem is when I try and connect via web app.

Does this make sense or do I need to clarify more?


这篇关于SQL连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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