Sql server 2005 SQL Server 2005,Windows身份验证,连接字符串出现错误“;“登录失败”;

Sql server 2005 SQL Server 2005,Windows身份验证,连接字符串出现错误“;“登录失败”;,sql-server-2005,connection-string,windows-authentication,Sql Server 2005,Connection String,Windows Authentication,我的桌面上安装了SQLServer2005和VisualStudio2005。 每次运行SQL Server 2005时,我都必须手动选择“以管理员身份运行”。我尝试过更改设置,但没有成功。所以我只能这样做。 但无论如何,这不是真正的问题 现在,当我在Visual Studio控制台应用程序中为Windows身份验证创建连接字符串时,它抛出了一个错误“登录失败” 我不熟悉.NET 代码如下: using System; using System.ComponentModel; using Sys

我的桌面上安装了SQLServer2005和VisualStudio2005。 每次运行SQL Server 2005时,我都必须手动选择“以管理员身份运行”。我尝试过更改设置,但没有成功。所以我只能这样做。 但无论如何,这不是真正的问题

现在,当我在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对象可能不正确。。语法应如下所示:

 SqlConnection conn = new SqlConnection(
            "Data Source=(local);Initial Catalog=VinOne;Integrated Security=SSPI");
SSPI代表安全支持提供者接口(如果您好奇的话)

还要检查服务作为什么用户运行,要执行此操作,请导航到运行。键入Services.msc,然后导航到SQL server,查看“作为登录”的值,并将其设置为当前登录的用户或Visual Studio运行的任何用户,我猜SQL server当前需要更高的权限


希望能成功!祝你好运。

我知道,这种奇怪的情况可以通过在管理模式下运行Visual Studio来解决(通过右键单击图标并选择“以管理员身份运行”),就像我在SQL Server 2005中所做的那样


非常感谢大家的支持和指导。

这是sql server还是sql server express?谢谢。这是sql server 2005而不是server express。谢谢。不,它也返回了相同的错误。我想知道的是,“以管理员身份运行sql。”“每次手动,是否会对打开与数据库的连接产生任何影响?