I am having troubles trying to autogenerate a token that all client-side users can use. Am using Oauth 2.0.
I can perfectly generate a token localhost, using Account controller /api/Account/Register, but when I publish the web api I cannot access with that token, and I also can't generate the token like I did localhost.
Is there any way to generate a token server-side like I do localhost?, it should be consistent in the way that when I republish the app that token should still be the same.
I am using Postman to test it. When I call /api/Account/Register with this json:
{
"Email": "da#a.com",
"Password": "sample striAng 21|",
"ConfirmPassword": "sample striAng 21|"
}
it returns me an error in like this:
{
"Message": "An error has occurred."
}
I am copying exactly what I did localhost, but on server doesn't work.
The problem is that you're connecting to a SQL Express Database on your local machine, but in most of the cases Servers don't use SQL Express (Nor have the same credentials when login to it) you MUST set up your web.config and sql connection.
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: 52 - Unable to locate a Local Database
Runtime installation. Verify that SQL Server Express is properly
installed and that the Local Database Runtime feature is enabled.)"
On your Web.config change/comment out your current connectionStrings and replace it with the one of your server
<connectionStrings>
<add name="YourDataBaseContextName" connectionString="Data Source=TheConnection;Initial Catalog=YourDataBaseName;User Id=TheUserOfDatabase;Password=YourHopeNotSoEasyPassword;" providerName="System.Data.SqlClient" />
</connectionStrings>
What i don't understand here is why I have a sql problem, being that Account controller never uses any database?
They do use it, after all you must save the register data on somewhere, right?
More specifically this lines register and save to database the model that you send:
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
it looks like 500 internal server error.
Any other endpoint is working all everything dosn't work?
You shold check connection string on server, and check if db exist and have proper tables.
Make sure that any envirement specyfic setting has valid value.
Related
I'm sure this has been asked before, but I'm not seeing anything in the similar questions. :(
I've got an ASP.NET MVC application I have developed locally that has been using a SQL Server Express database. In Azure, I recreated the database and taken the connection string it provided and updated the connection string in web.config of my app to use the new database.
When I publish the app to Azure, there doesn't appear to be any issues. However, when I hit a page in the app that accesses the db, it throws an error complaining it can't find the SQL Server Express database. Below is the main snippet from the error:
SqlException: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
So it seems like it's ignoring my connection string and still looking for a locally stored SQL Server Express database instead of using the Azure database I specify in the connection string. Any ideas why this might be? My guess is that I have missed something pretty basic (my usual guess when something that seems like it should be simple doesn't work. :) )
Connection strings per below request:
Local:
<add name="FCDbContext" connectionString="data source=(localdb)\MSSQLLocalDB;initial catalog=FormCenterResponder;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
Azure Contection String:
<add name="FCDbContext" connectionString="Server=tcp:***azuredbserver here***,1433;Initial Catalog=***azuredb here***;Persist Security Info=False;User ID=***username here***;Password=***password here***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />
And configureservices per another request (it's pretty much defaults):
public void ConfigureServices(IServiceCollection service)
{
services.AddControllersWithViews();
}
Ok, mark this one up to being a asp.net/c# noob. I'll go ahead and post (the embarrassing) answer, though, in case others find themselves in my position.
A co-worker had a look at the code and found an excellent tutorial here. He was able to figure out what I had done wrong.
Basically, I had never registered the database context in Startup.ConfigureServices. I think this is why someone (who has since deleted their question) asked me to post that section of my code. Then that context can be read in by the controller files granting them the info they need to get access to the db.
App is now working as it should.
Installed SQL Server Express 2014 & can connect/query with SSMS. I'm using Visual Studio 2015 (C#) and EF 6 to programatically connect to the server. In all the following scenarios I'm using the same connection string + am using the "sa" account with the correct password in the connection string.
When I sign in to the computer with a Windows domain account (ex: domain\username) then run the code it works fine.
When I sign in to the computer using a local account (ex: computername\username) account then run the code it fails with the following error: The underlying provider failed on Open. Note that I can launch and use SSMS w/out problems.
Here's my connection string.
metadata=res://*/[efName].csdl|res://*/[efName].ssdl|res://*/[efName].msl;provider=System.Data.SqlClient;provider connection string=\'Data Source=.\SQLExpress;Initial Catalog=db-name;Integrated Security=True;User ID=sa;Password=[psw];MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=False\'
I've tried with Integrated Security on or off (same result). Tried Data Source as ".\SQLExpress" or "[machineName]\SQLExpress" (same result).
After digging a bit I found the following entry in the Windows Event Viewer.
Level: Information
Source: MSQL$SQLEXPRESS
Task Category: Logon
Message: Login failed for user 'computername\username'. Reason: Failed to open the explicitly specified database 'db-name'. [CLIENT: ]
Looks to me like SQL Server windows service is using some kind of network auth prior to allowing a connection to SQL Server.
It's probably no surprise that the error message returned by EF/SQL didn't help at all. It has nothing to do with the underlying provider...
After some trial/error I've whittled it down to this. It's required that you set IntegratedSecurity=false when providing specific userName/Password credentials in the connection string. That's it.
I reinstaled my PC and now I have problems with my SQL connection string or with SQL Server 2012 Enterprise
Error I get:
"... (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)" or
"... (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
In SQL Server Management Studio server instance looks like this:
TOM-PC (SQL Server 11.0.3128 - Tom-PC\Tom)
And My SQL connection string in ASP.NET XML config. file:
<add name="ApplicationServices" connectionString="Data Source=.\TOM-PC;Database=D:\Programming\InvoiceManager\invocemanagerSQL.mdf;" providerName="System.Data.SqlClient" />
Tried everything, in firewall added port 1434 or 1433 tested both, not working, "SQL Server Browser" Service is running, TCP/IP Enabled, Allow remote connections to this server, even tried 4 different connection strings, nothing worked.
Before it worked like a charm, not fully but worked. Why not fully? Because I couldn't work on my local machine with both studios "VS2010" and "SQL Management studio" at the same time, if I needed change something in database manually, I needed to stop or restart SQL Server process and service, then I get in database, and read tables. Now, nothing is working!
What I do or did wrong? Where seems to be the problem? Why always are problems with SQL servers and it's connectionstrings?
What you are seeing in Management Studio is as follows:
Instance Name (SQL Server version - Domain\LoggedInUser)
You are logged in using integrated authentication (i.e. your windows logon account) but not specifying it in the connection string. This will try to use the currently logged on user for the ASP.Net application, which will almost certainly not be running as your windows account. It will either be one of the local or network service accounts or a built-in ASP.Net user.
You're also using the wrong variable name to attach the database file, if this is actually what you want rather than connecting to an actual database on the server.
What I suggest you do is enable SQL Server authentication on your instance, create a new user and give it permissions to the database as required.
You would then log in using the following format:
Server=myServerAddress; Database=myDataBase; User Id=myUsername; Password=myPassword;
Where myServerAddress would be localhost or TOM-PC; Database would be the name of the database as it appears in Management Studio; User Id would be the username for the user you just created and Password would be the password you set for them during creation.
If you do actually want to attach a database file then your connection string changes to use this format:
Server=myServerAddress; AttachDbFilename=C:\Path\To\Database\File.mdf; Database=myDataBase; Trusted_Connection=Yes;
Typically, you can get most connection string variants that you will need from: http://www.connectionstrings.com/sql-server/
I'm getting this error since I've moved my mvc3/entity framework site onto the live server from localhost. Normally when I would get this error, I'd check the database name, password and server are all correct in the connection string. I have checked this - they all seem fine.
I have aspnet Membership provider on the site within the database, and it allows me to login, verifies me, then tries to redirect me to another page, and then that's where the error happens - i.e., as soon as I connect to the database outwith the membership provider.
The database is on the same server as the site, and when I connect from localhost to the remote server, it works perfectly.
Here is the full error message:
Exception message: 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)
Here is the connection string:
<add name="ApplicationServices" connectionString="Data Source=192.168.1.43;Initial Catalog=BlueLadder;User Id=BlueLadderAdmin;Password=Auth1991;timeout=30" />
Anyone anything I could try?
Ok, despite my connection string in the web config, it was actually being ignored and the application was still trying to connect to a local version. Apparently you need to pass the connection string through the dbContext constructor, like so.
public Context()
: base("ConnectionString")
{
}
Question was answered here
Thanks for your help anyway.
Try removing the Data Source and Initial Catalog, and replace them with something like this:
Server=.\SQLEXPRESS;Database=BlueLadder;
I don't know if you're using SQLEXPRESS, so just modify accordingly if you're not.
Check if your server is accepting remote connections and has TCP/IP provider enabled. You can configure this using "Sql Server Configuration Manager" on your server
You could try specifying the named instance of your server. "Sql Server Configuration Manager" can tell you what instances are installed on your server.
Server = 192.168.1.43/MSSQLSERVER or
Server = 192.168.1.43/SQLEXPRESS
I get the above error when trying to run my .net app as it attempts to connect to a SQL database on another server.
The SQL connection string is using a trusted connection.
IIS has anonymous access switched off, and integrated windows authentication switched on.
The user the error relates to is "DOMAINNAME\IISSERVERNAME$"
Do I need to add user "DOMAINNAME\IISSERVERNAME$" as a login on the SQL server machine?
I expected my username to be passed around - i.e. if I have access to the SQL server then the application would run fine?
Thanks in advance.
EDIT: Should point out that I know it's authenticating OK from an IIS point of view... if I switch to anonymous access it fails my own security as an "Unknown User"... which is what I'm after
Try this as connection string
Data Source=localhost;Initial Catalog=dbname;Integrated Security=True;
Sorted it.
Had to add the user DOMAINNAME\IISSERVERNAME$ as a SQL login on that server.
As a side issue, then had to add execute permissions for that login to the schema.
Thanks for your help.