How does one connect an exsisting SQL Server to an ASP.NET forms application (Website) using built-in login controls within Visual Studio

0

Problem: I'm trying to create a login form using built-in (drag and drop) form controls in Visual Studio 2019. It's my first time using these controls as opposed to working with php and switched over for the sake of efficiency. So, I am attached to the idea of using the built-in method for login controls if at all possible.

My project is an ASP.NET Web Application (.NET Framework). I have a separate remote Microsoft SQL Server running and attached via the server explorer as well as a connection string in the web.config file as follows:

<add name="NAME" 
     connectionString ="Data Source=COMPUTERNAME;Initial Catalog=CATNAME;User ID=tj;Password=Password" 
     providerName="System.Data.SqlClient"/>

However, this does not help the main issue which is: how do make the login form I have created communicate with my remote SQL Server?

After reading through the stack trace and doing some research, I can conclude that I get the errors below [Results of stack trace] because of the fact that my project is not located in the "My Documents/Visual Studio 2019/..." directory and Visual studio itself is trying to access the actual directory, which it has no READ/WRITE privileges over (even though I tried manually adding those privileges myself), but anyway... Visual Studio would normally add the App_Data directory as well as a built-in database (not ideal) within it which would work with the built-in login controls as is. Instead VS is trying to access a place that it can't along with a database that doesn't exist. I have exhausted the options I know of and have no idea what to try next. I know there are many tutorials out there that cover the general topic, but they do not help my underlying issue or benefit me or my situation any which way since they do not go in depth on everything that can co wrong with a project or unique circumstances such as mine.

Also, the SQL Server is fine. It's been tested in several different ways and is accessible from Visual Studio.

Sources:

(Sorry, did some research before I decided to post, so I lost track of most of my sources)

Initial Tutorial:

Troubleshooting:

Results of stack trace:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]

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, SqlAuthenticationProviderManager sqlAuthProviderManager) +947
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +6024351
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +531
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) +156
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +22 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +92 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +219 System.Data.SqlClient.SqlConnection.Open() +101 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +78

[HttpException (0x80004005): Unable to connect to SQL Server database.] System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131 System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +92 System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +30 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +410`

c#
asp.net
sql-server
visual-studio-2019
asked on Stack Overflow Nov 25, 2019 by Tevin Johnson • edited Nov 25, 2019 by marc_s

1 Answer

0

As your error stated that your connection between your application and sql server is not successful, and further looking into your connection string as stated below

<add name="AnyName" connectionString ="Data Source="ComputerName";Initial Catalog=DBNAME;User ID=tj;Password=Password" providerName="System.Data.SqlClient"/>

In your "Data Source" section SQL Instance is missing like

"Data Source=ComputerName/SqlInstance"

answered on Stack Overflow Nov 25, 2019 by Syed Wahhab

User contributions licensed under CC BY-SA 3.0