0

I'm going through a book to teach myself ASP.NET. So far so good on it and even on SQL in SQL Developer but I can't connect from external apps.

I'm using Visual Studio 2010 Pro SP1, SQL Server 2008 R2 Standard and Windows 7 Professional SP1 using IIS 7.5. The language I'm using in ASP.NET is VB.NET but happy for C# answers.

I can never get the connection string working

connectionString="Server=ASUS-P5Q\MSSQLSERVER;Database=Dorknozzle; User Id=xxxxxxxxx; Password=xxxxxxxxx;"

I always get the following Error

Server Error in '/' Application.
Login failed for user 'ASUS-P5Q\xxxxxx'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'ASUS-P5Q\xxxxxxx'.

Source Error:

Line 17: conn.Open()**

I've switched off user account control, the anti-virus and the firewall but nothing works :-(

4

5 回答 5

0

The error message appears to indicate that you are using Integrated Authentication (the Windows username and password). There are a number of reasons this could be failing.

For simplicity's sake, you may also try using Sql authentication: create a user in Sql and specify that username and password in your connection string. I usually start out with a Sql username and password and then decide on my final authentication method before deployment.

于 2013-03-31T00:34:54.503 回答
0

To connect to a local database engine, you can use the .\ syntax as in: .\sql2008:

connectionString="Server=.\MSSQLSERVER;Database=Dorknozzle; User Id=xxxxxxxxx; Password=xxxxxxxxx;Integrated Security=false;"
于 2013-03-31T00:35:05.347 回答
0

As @MTAdmin noted, you seem to use integrated authentication..

You can only use your login as the credentials when using this method, so make sure your app pool is running as that user ('ASUS-P5Q\xxxxxx' in this case) and use the following connection string.

Server=ASUS-P5Q\MSSQLSERVER;Database=Dorknozzle;Integrated Security=SSPI;

For future reference, I recommend using ConnectionStrings.com when you forget that sneaky connections string as I always do.

于 2013-03-31T01:03:49.390 回答
0

How I fixed my issue was that I created a user under SQL Management Studio and used SQL Server user authentication. This is the string that worked for me in the end...

connectionString="Data Source=ASUS-P5Q\MSSQLSERVER,1433;Initial Catalog=Dorknozzle;Integrated Security=False;User ID=SQLDT;Password=####" providerName="System.Data.SqlClient" />

Thanks guys for your help :)

于 2013-10-10T01:03:10.327 回答
0
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace User_Management
{
    class DatabaseConnection
    {
        public string GetConnectionString()
        {
            return @"server=AFORE\MSSQLSERVER; Integrated Security=SSPI; Database = prictice;";
        }

        public SqlConnection GetConnectionObj()
        {
            SqlConnection connectionObj=new SqlConnection(GetConnectionString());
            connectionObj.Open();
            return connectionObj;
        }
        public void ExecuteSqlCommandAndCloseConnection(string insertQueryString, SqlConnection connectionObj)
        {
            SqlCommand sqlCommandObj = new SqlCommand(insertQueryString, connectionObj);
            sqlCommandObj.ExecuteNonQuery();
            connectionObj.Close();
        }
        public void ExecuteSqlCommandOnly(string insertQueryString, SqlConnection connectionObj)
        {
            SqlCommand sqlCommandObj = new SqlCommand(insertQueryString, connectionObj);
            sqlCommandObj.ExecuteNonQuery();

        }
    }
}
于 2013-10-10T01:16:30.973 回答