SQL 2008的连接字符串 [英] Connection String for SQL 2008

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

问题描述

我使用Dreamweaver CS5,asp.net C#作为前端,并使用SQL 2008作为后端.这基本上就像一个库存系统.所以我只写了一个小程序来测试我的连接.我的问题是,当我尝试建立连接时出现错误:

I am using Dreamweaver CS5, asp.net C# as my frontend, and SQL 2008 as my backend. This is basically like a inventory system. so i just wrote a small program to test my connection. My problem is that when i try to establish a connection i get an error:

void Page_Load()
{
  string connectionString ="Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Integrated Security=SSPI;" ;

  SqlConnection con = new SqlConnection(connectionString);

  try{
      //try to open connection
      con.Open();
      lblInfo.Text = "Server Version: " + con.ServerVersion;
      lblInfo.Text = "<br />Connection Is: " + con.State.ToString();
  }
  catch(Exception err)
  {
      //Handle an error by displaying the information
      lblInfo.Text = "Error reading the database. " + err.Message;
  }
  finally
  {
      //make sure conneciton is closed
      con.Close();
      lblInfo.Text += "<br />Now Connection Is: " +
      con.State.ToString();
  }


结果:

读取数据库时出错.用户某人"登录失败

我的网络服务器名称在哪里.我想要的是该用户需要是当前用户,所以这将是我的名字,因为该用户尝试通过Windows身份验证连接到sql.我的SQL数据库具有可以读写的用户.所以我被困住了,真的不知道如何解决这个简单的问题.谢谢.任何帮助将是非常有用的帮助.


Result:

Error reading the database. Login failed for user ''someone''

where someone is my webserver name. what i want is that user needs to be the current user, so it would be myname as the user trying to connect to sql with windows authentication. My SQL db has users that can read and write to it. so i am stuck and don''t really know how to fix this simple problem. Any help would be of great help, thanks.

推荐答案

显然,用户需要访问数据库的权限.您可以创建一个Windows组并在其中放置每个用户,然后以适当的权限将该组添加到SQL Server.您还可以使用应用程序角色 [
Obviously the users need to have access to the database. You can create a Windows group and place each user in it, then add that group to the SQL server with the appropriate rights. You can also use Application Roles[^]. However, the much more common approach in ASP.NET is to create a SQL Server user for this application and use it rather than Windows users.


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

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