October 26, 2016 at 4:01 pm
Hi, the code below successfully inserts a new user into my database:
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports System
Imports System.Linq
Namespace WebFormsIdentity
Public Class Register
Inherits System.Web.UI.Page
Protected Sub CreateUser_Click(ByVal sender As Object, ByVal e As EventArgs)
' Default UserStore constructor uses the default connection string named: DefaultConnection
Dim userStore = New UserStore(Of IdentityUser)
Dim manager = New UserManager(Of IdentityUser)(userStore)
Dim user = New IdentityUser
user.UserName = UserName.Text
Dim result As IdentityResult = manager.Create(user, Password.Text)
If result.Succeeded Then
StatusMessage.Text = String.Format("User {0} was created successfully!", user.UserName)
Else
StatusMessage.Text = result.Errors.FirstOrDefault
End If
End Sub
End Class
End Namespace
However if I add the following code:
Profile.PostCode = PostCode.Text
Profile.VisitedOn = DateTime.Now
Profile.Save()
and this in web.config:
<profile>
<properties>
<add name="PostCode" allowAnonymous="true"/>
<add name="VisitedOn" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>
it gives the following error:
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).
[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) +1394
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +664
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +57
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1222
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +211
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +393
System.Data.SqlClient.SqlConnection.Open() +122
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +83
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +173
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +113
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +51
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +469
Any ideas on what's causing this? I've tried restarting SQL Server, the connection must be fine as if I remove the few lines of code from the vb page it connects and can add a new user. If I add the code back in it suddenly can't connect.
Thanks
October 27, 2016 at 6:41 pm
It looks to me like your .NET application can't find the SQL Server. You define a connection string used to connect to the database. This can be done in code or in the web.config. This is where you specify the server name, login and password to connect. Check it out and make sure it's correct.
October 28, 2016 at 4:31 pm
Yeah that's all fine, the connection is made fine but as I said if I add in those three lines of code the server cannot be found.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply