2 Replies - 574 Views - Last Post: 03 October 2012 - 08:02 AM Rate Topic: -----

#1 dbca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-September 12

Updating SQL Server through ASP.NET

Posted 03 October 2012 - 06:40 AM

Trying to update record in SQL Server database and having trouble making the connection to the database:

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource = @".\SQLEXPRESS";
            builder.InitialCatalog = "database";
            builder.IntegratedSecurity = true;

            SqlConnection linkToDB = new SqlConnection(builder.ConnectionString);
            linkToDB.Open();

            using (linkToDB)
            {
                commandWrapper.Connection = linkToDB;
                commandWrapper.ExecuteNonQuery();
            }



When I execute the code I receive the following error:

Cannot open database "database" requested by the login. The login failed.
Login failed for user 'computername\username'.

Line 151:
Line 152: SqlConnection linkToDB = new SqlConnection(builder.ConnectionString);
Line 153: linkToDB.Open();
Line 154:
Line 155: using (linkToDB)


The error is at Line 153 ->
How can I open the connection to the database? Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Updating SQL Server through ASP.NET

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1182
  • View blog
  • Posts: 1,677
  • Joined: 24-August 11

Re: Updating SQL Server through ASP.NET

Posted 03 October 2012 - 07:26 AM

Check out www.connectionstrings.com for help setting up the parameters of your connection string. I don't know which version of SQL Server you're using, but there is plenty of examples for SQL Server Express at the bottom of the SQL Server 2008 entry, for example. This has some good information about connection strings to help.
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Updating SQL Server through ASP.NET

Posted 03 October 2012 - 08:02 AM

You need to make sure that the user that is trying to access the database actually has rights to do so. if you download Sql Server Management Studio and connect to your SQL express instance you are able to dive into the database security to find out which logins have access to the database.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1