Unable to connect to master or target server "ServerName" - c#

Have some troubles with Unit Test and Dackpack. This is the full error name:
DeploymentFailedException: Unable to connect to master or target server 'DBTests'. You must have a user with the same password in the master or target server 'DBTests'.
I have 3 strange things :
I can publish my Database on Server (tests have the same connection string)
I can log in in my site and I don't have troubles with DB (using IIS)
Test logic: Test database created when I init my tests, and it is really created!!!!
But all tests have "Error".
I upgrade my SSDT. I reinstall MSSQL Twice. And I set compability level(130). And what is so funny this is my Connection Strings when I try to debug my tests:
"Data Source=ServerName;integrated security=false;Initial Catalog=DbTests;User ID=kek;Password=kek;Connection Timeout=60;MultipleActiveResultSets=True;Max Pool Size=1024"
That is TestDatabase connection string. And she is absolutely fine because I TESTED this connection string.
This is masterDatabase connection string:
Data Source=ServerName;integrated security=false;Initial Catalog=master;User ID=kek;Password=kek;Connection Timeout=60;MultipleActiveResultSets=True
And the main question what I have: Why Error say what 'DBTest' - this is a server ?? I mean, this is DB, not server.
Maybe someone knows about that, idk. That is so stupid and I can't understand what's wrong.
UPD: I solve my problem. Installed SQL Server 2016.
P.S. Ofc I can log in on the server with my "kek", "kek" credentials in Management Studio.

Related

ASP.NET MVC: moving from SQL Server Express to Azure

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.

Connection to Oracle database not working

I am currently working on a project with someone. We are connecting to a oracle Database using the NuGet Package Oracle.ManagedDataAccess.Core.
We are connecting using a connection string that looks like this:
"User Id={this._dbUser};Password={this._dbPassword};Data Source={this._dbServer};"
The Parameters we pass on are correct we checked multiple times.
At first I got a Connection Timed out error which we fixed by adding persist security info=false;Connection Timeout=120; to the connection string.
At first it seemed to be working but then we encountered a new error.
This time it was saying:
Oracle communication: Connection to server could not be established or connection string not parsed
(Might not be 100% accurate because I had to translate it from German to English)
We could not find a solution for this error but we discovered that the error only gets thrown when we run the code on my machine. His is doing totally fine and can connect without any problems.
Could it be that I have some settings set on my machine that would prevent me from accessing the Database?

Unable to connect to SQL Server Express 2014 when signed in with local account

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.

Error Database schema could not be retrieved for this connection

Edit: if you are downvoting can you at least tell me what Im missing so I can improve my question?
I have a website which uses a SQL Server database. It works fine when building both debug and release.
But if I add a new SqlDataSource to my project and try to configure it in design view, I get this error:
Database scheme could not be retrieved for this connection. Please make sure the connection settings are correct and that the database is online.
Failed to retrieve data for this request.
Failed to connect to server---------.
Login failed for user 'xxxxxx'.
Even if I configure the connection string with the connection-guide, test the connection and save, it fails afterwards when trying to configure the datasource.
Connection string:
Data Source=SERVER\SQLEXPRESS,61180;Initial Catalog=DBNAME;User Id=USERNAME;Password=PASSWORD;
So to clarify: The connection string works fine when running the website in both debug and release, and if I connect using SQL Server Management Studio, but the only place it doesn't work is when I try to configure the datasource in design view.
After a lot of trial and error I found out that I had to put Persist Security Info=True; into the connectionstring to get it to work.
First time in my 10+ years of programming that I encountered this problem.

Data source for connection string

What connection string should I use if SSMS connects to it using simply machine name, without instance name?
I mean it connects using the following string: PCName
I used to connect using PCName/SQLExpress. I cannot set correct connection string in my app in order to connect app to database on this machine.
How can I check what data source I should use? I've checked in Sql Server configuration that server instance named as SQLEXPRESS.
So I tried data source as:
.\SQLEXPRESS
PCName\SQLEXPRESS
.
I'm trying to connect to a service-based database, located in my app folder. So I'm using the following connection string:
data source=PCName;attachdbfilename=|DataDirectory|\spareparts.mdf;integrated security=true;user instance=true;multipleactiveresultsets=true;App=EntityFramework;
If SSMS connects via PCName then your application should be able to use Data Source=PCName. However it depends on whether your application is on the same machine as SSMS or not. If on a different machine it might not be able to connect for a variety of reasons. We can't speculate what the problem might be if all you do to describe the issue is "It won't connect" - what does that mean? Do you get an error message? If so, what is it? Make sure:
SQL Browser service is started
TCP/IP is enabled
Add Network=DBMSSOCN; to the connection string
You've also tried the IP address in addition to PCName
Firewall isn't blocking the SQL Server port

Categories

Resources