Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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();
  }

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.
Posted
Updated 5-Oct-10 13:31pm
v2

1 solution

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.
 
Share this answer
 
Comments
ajep 5-Oct-10 23:22pm    
So you are suggesting instead of using windows authentication, I should create a user and password that would be used by all the users when connecting to the database.
[no name] 6-Oct-10 0:16am    
As I said, for an asp.net application that is the most common approach. Unless you have a specific need to control database on a per user basis
ajep 6-Oct-10 11:26am    
Thanks, i will then implement this for web application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900