I'm trying to connect to a local Sql Server 2012 database instance trough Visual Studio 15 using connection string. While I've been able to connect to the DB through the Visual Studio SQL Server Object Explorer and run a test procedure successfully, I'm unable to do so in my project using connection string.
Here's my connection string that was given by the SQL Server Object Explorer
<connectionStrings>
<add name="objConnLocal"
connectionString="Data Source=DESKTOPIVO;Integrated Security=True;Initial Catalog=tnk;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;"providerName="System.Data.SqlClient"/>
</connectionStrings>
Here's my code that works perfectly fine connecting to an Azure DB with Azure given connection string (the code works)
public class DbConn
{
public static string DatabaseConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["objConnLocal"].ConnectionString;
public static SqlConnection objConn = new sqlConnection(DatabaseConnectionString);
public void spCMSSelectTest(out DataSet ds)
{
ds = new DataSet("buttons");
SqlDataAdapter objDataAdapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("spCMSSelectTest", DbConn.objConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
objDataAdapter.SelectCommand = cmd;
objDataAdapter.Fill(ds);
cmd.Connection.Close();
}
}
And this is the DB I'm trying to connect to:
Here's the test Page I'm trying to access:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds;
try
{
dbc.spCMSSelectTest(out ds);
lblTest.Text = ds.Tables[0].Rows.Count.ToString();
}
catch (Exception easd)
{
lblTest.Text = easd.ToString();
}
}
I've been going trough answers here and on google but nothing seemed to work for me. What Am I missing?
EDIT: There's the error:
System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'IIS APPPOOL\DefaultAppPool'. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at DbConn.spCMSSelectTest(DataSet& ds) in c:\inetpub\wwwroot\CMS\App_Code\DbConn.cs:line 22 at index.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\CMS\index2.aspx.cs:line 18 ClientConnectionId:d576fae4-db3d-451d-8436-2abe003c01f0 Error Number:18456,State:1,Class:14