简单的ADO问题 [英] Simple ADO problem

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

问题描述

我运行以下操作,我得到一个消息框告诉我连接

已关闭(目前为止确定)然后崩溃了。错误消息是:SQL

服务器不存在或访问被拒绝。


SQL管理器正在运行,我通过运行旧的ADO测试它
分配(有效)。所以我不确定我做错了什么

以下的简单代码...


我的代码如下。

===

使用System;

使用System.Windows.Forms;

使用System.Data.SqlClient;


公共类ConnectionTest

{

public static void Main()

{

try

{

SqlConnection myConnection = new SqlConnection(" Initial

Catalog = Northwind; Data Source = localhost; Integrated安全= SSPI;");

MessageBox.Show(" Connection is" +

myConnection.State.ToString());


myConnection.Open();

MessageBox.Show(" Connection is" +

myConnection.State.ToString());


myConnection.Close();

MessageBox.Show(" Connection is" +

myConnection.State.ToString() );

}

catch(exception ex)

{

MessageBox.S怎么样(ex.Message);

}

}

}

I run the following and I get a messagebox telling me the connection
is closed (OK so far) and then it crashes. The error message is: SQL
Server does not exist or access denied.

SQL Manager is running and I tested it by running an older ADO
assignment (which worked). So I''m not sure what I''m doing wrong with
the following bare-bones code...

My code follows.
===
using System;
using System.Windows.Forms;
using System.Data.SqlClient;

public class ConnectionTest
{
public static void Main()
{
try
{
SqlConnection myConnection = new SqlConnection("Initial
Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;");
MessageBox.Show("Connection is " +
myConnection.State.ToString());

myConnection.Open();
MessageBox.Show("Connection is " +
myConnection.State.ToString());

myConnection.Close();
MessageBox.Show("Connection is " +
myConnection.State.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

推荐答案

Alex< a@b.c>写在

新闻:du ******************************** @ 4ax.com:
Alex <a@b.c> wrote in
news:du********************************@4ax.com:
我运行以下操作并收到一个消息框,告诉我
连接已关闭(目前为止确定)然后崩溃了。错误
消息是:SQL Server不存在或访问被拒绝。

SQL管理器正在运行,我通过运行较旧的ADO
分配(有效)对其进行了测试。所以我不确定我做错了什么
使用以下简单的代码......
I run the following and I get a messagebox telling me the
connection is closed (OK so far) and then it crashes. The error
message is: SQL Server does not exist or access denied.

SQL Manager is running and I tested it by running an older ADO
assignment (which worked). So I''m not sure what I''m doing wrong
with the following bare-bones code...




Alex,


你的代码在我的机器上工作正常。


有些事要尝试:


- 确保你有SQL服务器设置为使用集成的

或混合模式安全性(请参阅混合模式安全性,然后在/ b
,SQL服务器在线预订了解更多信息)

- 更改连接字符串以使用用户名/密码

而不是集成安全性。

- 使用MS数据连接编辑器构建和测试

连接字符串。如果你没有Visual Studio,你可以通过创建一个带有UDL

文件扩展名的空文件来调用编辑器。 (该扩展名已在

编辑器中注册)。双击该文件将显示

数据连接编辑器。您构建的连接字符串将以INI格式保存到UDL文件中。

- 查看 www.connectionstrings.com 获取更多提示。


希望这会有所帮助。


克里斯。

-------------

CR Timmons Consulting,Inc。
http://www.crtimmonsinc.com/



Alex,

Your code works fine on my machine.

Some things to try:

- Make sure you have SQL server set up to use either integrated
or mixed-mode security (see "mixed mode security" in
the SQL server books online for more info)
- Change your connection string to use a username/password
instead of integrated security.
- Use the MS Data Connection editor to build and test a
connection string. If you don''t have Visual Studio, you
can invoke the editor by creating an empty file with a "UDL"
file extension. (that extension is registered with the
editor). Double-clicking on the file will bring up the
Data Connection editor. The connection string you build will
be saved to the UDL file in INI format.
- Check out www.connectionstrings.com for some more tips.

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/


2004年4月7日星期三23:06:33 -0700,Chris R. Timmons

< crtimmons@X_NOSPAM_Xcrtimmonsinc.com>写道:
On Wed, 07 Apr 2004 23:06:33 -0700, "Chris R. Timmons"
<crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote:
Alex,

您的代码在我的机器上正常工作。

有些事情要尝试:

- 确保您已将SQL服务器设置为使用集成的
或混合模式安全性(请参阅在线SQL服务器书籍中的混合模式安全性以获取更多信息)


我正在使用neutered sqlmangr.exe版本(不是真正的SQL Server)。

但是,我不认为这是问题所在。 。

- 更改连接字符串以使用用户名/密码
而不是集成安全性。


我想让这个安全和通用但是,我再也不认为这是

是问题...

- 使用MS数据连接编辑器构建和测试
连接字符串。如果您没有Visual Studio,则可以通过创建带有UDL文件扩展名的空文件来调用编辑器。 (该扩展名已在
编辑器中注册)。双击该文件将显示
数据连接编辑器。您构建的连接字符串将以INI格式保存到UDL文件中。


我做到了 - 这就是我最终得到的连接字符串。我还按了测试连接按下
没有错误/警告的按钮。

- 查看 www.connectionstrings.com 获取更多提示。
Alex,

Your code works fine on my machine.

Some things to try:

- Make sure you have SQL server set up to use either integrated
or mixed-mode security (see "mixed mode security" in
the SQL server books online for more info)
I''m using the neutered sqlmangr.exe version (not the real SQL Server).
But, I don''t think this is the problem...
- Change your connection string to use a username/password
instead of integrated security.
I want to make this secure and generic but, again, I don''t think this
is the problem...
- Use the MS Data Connection editor to build and test a
connection string. If you don''t have Visual Studio, you
can invoke the editor by creating an empty file with a "UDL"
file extension. (that extension is registered with the
editor). Double-clicking on the file will bring up the
Data Connection editor. The connection string you build will
be saved to the UDL file in INI format.
I did that - that''s how I ended up with my connection string. I also
pressed the "test connection" button with no errors/warnings.
- Check out www.connectionstrings.com for some more tips.




真正奇怪的是,在VB中,这个相同的代码似乎有效。所以

我得出的结论是我的C#代码一定有问题你还是

告诉我我的代码工作正常。

我的代码再次(不同的版本,但仍然给我相同的

问题):


===

使用System;

使用System.Windows.Forms;

使用System.Data.SqlClient;


公共类ConnectionTest

{

SqlConnection(connectionString);

public static void Main()

{

尝试

{

string connectionString =" Integrated Security = SSPI; Persist

安全信息=假;初始目录= CI632Appointments;数据

来源= alex-jayme \\\
etsdk" ;;

SqlConnection myConnection = new

SqlConnection(connectionString);


MessageBox.Show(" Connection is" +

myConnection.State.ToString());


myConnection .Open();

MessageBox.Sho w(连接是, +

myConnection.State.ToString());


myConnection.Close();

MessageBox.Show("连接是+

myConnection.State.ToString());

}

catch(exception ex)

{

MessageBox.Show(ex.Message);

}

}

}



What''s really weird is that, in VB, this same code seems to work. So
I''m left with the conclusion that my C# code must be at fault yet you
have told me my code works fine.

My code again (different version but still giving me the same
problem):

===

using System;
using System.Windows.Forms;
using System.Data.SqlClient;

public class ConnectionTest
{
SqlConnection(connectionString);
public static void Main()
{
try
{
string connectionString = "Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=CI632Appointments;Data
Source=alex-jayme\netsdk";
SqlConnection myConnection = new
SqlConnection(connectionString);

MessageBox.Show("Connection is " +
myConnection.State.ToString());

myConnection.Open();
MessageBox.Show("Connection is " +
myConnection.State.ToString());

myConnection.Close();
MessageBox.Show("Connection is " +
myConnection.State.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}


Alex< a@b.c>写在

新闻:1g ******************************** @ 4ax.com:
Alex <a@b.c> wrote in
news:1g********************************@4ax.com:
真正奇怪的是,在VB中,这个相同的代码似乎有效。所以我得出的结论是我的C#代码必须处于故障状态但你告诉我我的代码工作正常。

我的代码再次(不同的版本,但仍然给我相同的问题):

string connectionString =" Integrated
Security = SSPI; Persist
安全信息= False;初始目录= CI632Appointments;数据
来源= alex-jayme \\\
etsdk";
What''s really weird is that, in VB, this same code seems to
work. So I''m left with the conclusion that my C# code must be at
fault yet you have told me my code works fine.

My code again (different version but still giving me the same
problem):

string connectionString = "Integrated
Security=SSPI;Persist
Security Info=False;Initial Catalog=CI632Appointments;Data
Source=alex-jayme\netsdk";




Alex,


\ n导致错误。这会在字符串中添加换行符。

要么转义它(\\ n),要么在整个字符串前加上@

符号(例如@" Integrated安全;坚持......)


希望这会有所帮助。


克里斯。

--- ----------

CR Timmons Consulting,Inc。
http://www.crtimmonsinc.com/


这篇关于简单的ADO问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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