Sql server 使用Windows身份验证或sql身份验证访问localhost\SQLEXPRESS需要使用什么sql连接字符串?

Sql server 使用Windows身份验证或sql身份验证访问localhost\SQLEXPRESS需要使用什么sql连接字符串?,sql-server,Sql Server,我已经在我的电脑上安装了SQL Express,希望做一些创建表然后修改表的练习。我在VisualStudio中编写了一个网页,基本上是从SQLEXPRESS中的表中选择*,但我永远无法让连接字符串工作。请帮忙 我的连接字符串 资料 Source=localhost\SQLEXPRESS;最初的 目录=测试;使用者 Id=xaa9 PC\xaa9;密码=abcd 错误消息: 查询是从TBL客户中选择* 其中username='johndoe'错误为 用户“x309 PC\x309”登录失败 描述

我已经在我的电脑上安装了SQL Express,希望做一些创建表然后修改表的练习。我在VisualStudio中编写了一个网页,基本上是从SQLEXPRESS中的表中选择*,但我永远无法让连接字符串工作。请帮忙

我的连接字符串

资料 Source=localhost\SQLEXPRESS;最初的 目录=测试;使用者 Id=xaa9 PC\xaa9;密码=abcd

错误消息:

查询是从TBL客户中选择* 其中username='johndoe'错误为 用户“x309 PC\x309”登录失败

描述:未处理的异常 在执行过程中发生 当前web请求。请检查 有关堆栈跟踪的详细信息,请参阅 错误及其来源 密码

异常详细信息:系统。异常: 查询是从TBL客户中选择* 其中username='johndoe'错误为 用户“x309 PC\x309”登录失败

试着这样做:

string connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=test;User Id=x309;Password=abcd;";

还要确保您有。

尝试使用Windows身份验证:

Data Source=localhost\SQLEXPRESS;Initial Catalog=test;Integrated Security=SSPI;

如果要将数据连接字符串放置在web.config文件中,请按如下方式指定连接:

<connectionStrings>
<add name="NorthwindConnString" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>
</connectionStrings>

即使是Scott Hanselman也会忘记…

这是一个Windows域\用户名,因此SQL身份验证不是可行的方法,您需要集成身份验证。@Ben,使用Windows身份验证时,您不会在连接字符串中指定用户名和密码。连接字符串中不需要转义。我假设字符串不是C语言的,因为编译器会给出一个无法识别的转义序列错误\S@Andomar,我认为连接字符串中的\x有问题,因为它被视为十六进制。@Darin Dimitrov:看来SQL Server登录中不允许使用反斜杠。因此,他可能正在尝试使用Windows身份验证登录,他的电脑名为xaa9 PCCheck out-它显示了人类已知的SQL Server连接字符串的所有可能组合和变体。。。
"Data Source=.\\\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=SHANU-PC\SQLEXPRESS;Initial Catalog=Anusha;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {

        con.Open();
        SqlCommand cmd=new SqlCommand("select * from tbl_state",con);

        SqlDataAdapter da=new SqlDataAdapter(cmd);

        DataTable dt=new DataTable();
        da.Fill(dt);
            DropDownList1.DataSource = dt;
            DropDownList1.DataTextField = "sname";
            DropDownList1.DataValueField = "sid";
            DropDownList1.DataBind();

        con.Close();
        }