我的桌面上安装了SQL Server 2005和Visual Studio 2005。每次运行SQL Server 2005时,我都必须手动选择"run AS ADMINISTRATOR"。我试过更改设置,但没有成功。所以我只能这样做。但无论如何,这并不是真正的问题。
现在,当我在Visual Studio控制台应用程序中为Windows身份验证创建连接字符串时,它会抛出一个错误"登录失败"。
我是.NET 的新手
代码如下:
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
public class Vin
{
public static void Main()
{
Console.WriteLine("Hello World!!!");
SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=VinOne; Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from Prod", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine("Got It!!!");
}
Console.Read();
}
}
SqlConnection conn = new SqlConnection(
"Data Source=(local);Initial Catalog=VinOne;Integrated Security=SSPI");
SSPI代表安全支持提供商接口(如果你好奇的话)
还要检查服务的运行身份,要执行此操作,请导航到Run。键入Services.msc,然后导航到SQL server,查看"登录为"的值,并将其设置为您当前登录的用户或Visual Studio运行的任何用户,我猜SQL server当前需要更高的权限。
希望能奏效!祝你好运
我知道,这种奇怪的情况可以通过在管理模式下运行Visual Studio(右键单击图标并选择"以管理员身份运行")来解决,就像我在使用SQL Server 2005时一样。
非常感谢大家的支持和指导。