Unable to connect to localdb on Visual Studio 2013 using angular-js - angularjs

I'm following this tutorial : http://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angularjs-free-e-book/
And below is the connection string:
<add name="HomeCinema" connectionString="Data Source=(LocalDb)\v11.0;
Initial Catalog=HomeCinema;Integrated Security=SSPI;
MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
When I try to run update-database -verbose on the command-line, I'm getting 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)
I'm trying to connect to the LocalDB that comes with Visual Studio 2013.
When I look at the output:
Target database is: 'HomeCinema'
(DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
This is the constructor:
public HomeCinemaContext()
: base("HomeCinema")
{
Database.SetInitializer<HomeCinemaContext>(null);
}
Thank you.

I know this is already old, but what I did to run the command successfully was set HomeCinema.Data as the startup project before running the update-database -verbose command. I think this is so that the command will use the app.config in the HomeCinema.Data project where the connection string is specified.
Referring to one of the comments in the article, I think you can also use the following command. This is assuming that you have HomeCinema.Web as your startup project and that your connection string is set in the Web.config.
update-database -verbose -ProjectName "HomeCinema.Data" -StartupProjectName "HomeCinema.Web" -ConnectionStringName "HomeCinema"

Related

Getting an error message from a sql server driver in my symfony project

I have tried to install the ODBC driver 18 for SQL Server in my symfony project. I am getting the following error messages. I wanted to ask if anyone could knows the solution for these.
An exception occurred in the driver: SQLSTATE[08001]: [Microsoft][ODBC
Driver 18 for SQL Server]SSL Provider: [error:16000069:STORE
routines::unregistered scheme:scheme=file][error:80000002:system
library::No such file or direc tory:calling
stat(/usr/local/etc/openssl#3/certs)][error:16000069:STORE
routines::unregistered scheme:scheme=file]
Environment details:
symfony version: 5.4.16
php8.1
Homebrew 3.6.16
apache 2.4.54
#AlwaysLearning's answer did help me.From the article linked, I checked the openssl#3 folder and I did see there was a cert.pem file. I then created a certs directory and copied the cert.pem file into that directory. That got of rid of my error message.
I did encounter an additional issue where I needed to add TrustServerCertificate parameter to the end of my connection string that is used to connect to the SQL server.
;TrustServerCertificate=1

Visual Studio 2022 localdb ((localdb)\MSSQLLocalDB) (ASP.NET Core)

Visual Studio 2022 localdb ((localdb)\MSSQLLocalDB) (running on ASP.NET Core).
My problem is: I want to change from VS2019 to VS2022.
VS2019 and SSMS works totally fine. localdb works
VS2022 have from the first installation no connection to localDB
I can create a new DB and connect it but that is not what I want. I want the connection to the localDB.
What I already tried:
Reinstall VS2022
Reinstall localDB
Disconnect VS2019 and VS 2022 and reconnect. VS2019 works and VS2022 does not
I also followed the Microsoft docs; nothing helped
Followed many Stack Overflow discussions
If I try to connect to (localdb)\MSSQLLocalDB, I get this 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) (.Net SqlClient Data Provider)
If I try to start the ASP.NET Core app, I get this error:
IOException: IDX20807: Unable to retrieve document from: 'System.String'. HttpResponseMessage: 'System.Net.Http.HttpResponseMessage', HttpResponseMessage.Content: 'System.String'.
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)
InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurat ionAsync(CancellationToken cancel)
I know this problem is really wired, but maybe one of you has an idea that helps.
I'm thankful for any help. :)
i was asking the question and found a solution.
Open CMD (windows + R)
SqlLocalDB.exe s MSSQLLocalDB
SqlLocalDB.exe i MSSQLLocalDB
Copy the path of Instance pipe name:. it should be something like: np:\......
use the path as servername when you in go to visual studio -> Add SQL Server
this works for me.
Follow up to above answer:
o Open CMD window
o cd C:
o dir SqlLocal*.exe /s /p
this should give you the path to localdb provider
o cd C:\Program Files\Microsoft SQL Server\150\Tools\Binn
Find your instance name
o SqlLocalDB.exe i
o SqlLocalDB.exe start to start the default instance

sqlcmd not working in Docker container that was created with Terraform

I'm trying to have a SQL Server Docker container run and have a database backup file restored using Terraform. So far I can get the SQL server Docker image to download and run as a container but I can't get the sqlcmd to run inside the container. I have it set up where the sqlcmd runs automatically when the container starts. This is the log message I get in the container:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
This is my terraform file:
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {
host = "npipe:////.//pipe//docker_engine"
}
resource "docker_image" "mssql" {
name = "mcr.microsoft.com/mssql/server:2019-latest"
keep_locally = true
}
resource "docker_container" "mssql" {
image = docker_image.mssql.latest
name = "sqldatabase"
attach = false
rm = false
restart = "no"
command = [ "/opt/mssql-tools/bin/sqlcmd", "-S localhost", "-U mssql", "-P <StrongPassword>" ]
env = [
"ACCEPT_EULA=Y",
"MSSQL_SA_PASSWORD=<StrongPassword>"
]
ports {
internal = 1433
external = 1433
}
}
I'm following this Microsoft tutorial about restoring a SQL Server database in a Docker container: https://learn.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15
Right now I'm just trying to run sqlcmd in the container to see if it works then I'll try restoring an actual database backup. How do I get the sqlcmd to work? I'm brand new to Terraform.
UPDATE:
As #Nick.McDermaid suggested, I ran the sqlcmd manually in the container and it worked. Also the username I had was wrong. It should be SA, not mssql. I got throw off because in the container log it says This container is running as user mssql. which must be different from a SQL Server username.
As #AlwaysLearning suggested it is a timing issue, Terraform starts the Docker container and runs sqlcmd when SQL Server is not ready.
I guess I need some kind of entrypoint.sh file that Terraform can run.
Please replace
command = [ "/opt/mssql/bin/sqlservr","--accept-eula"]

liquibase.exception.DatabaseException: Connection could not be created with driver com.microsoft.sqlserver.jdbc.SQLServerDriver

I am developing my application in SpringBoot which uses liquibase to update my ms-sql database.
This worked fine till now, but now I am trying to update everything to the latest version:
I changed java from 15 to 17.
I also updated liquibase-maven-plugin to 4.5.0.
mssql-jdbc dependency for liquibase is: mssql-jdbc:9.4.0.jre16
The new mssql-jdbc_auth-9.4.0.x64.dll file is moved to this folder:
c:\apps\Java\x64\jdk-17\bin\ (this is my java location).
My IntelliJ is set to use java 17 (JAVA_HOME is also configured to
the 17 path)
the version of Microsoft SQL Server Express (64-bit): 11.0.2100.60
So I think I did everything, but still, when I try to run my maven, I get the following error:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:4.5.0:update (myDatabase) on project my-project:
[ERROR] Error setting up or running Liquibase:
[ERROR] liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:sqlserver://localhost:1433;databaseName=My_Database;integratedSecurity=true with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]"

SQL Server installation is either corrupt or has been tampered with error getting instance id from name

I installed SQL Server 2012 now. When I try to open the exe file from the installed path,
C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn
I get the following error:
SQL Server installation is either corrupt or has been tampered with error getting instance id from name
I tried through command prompt too. I uninstalled again and tried again also and facing the same problem. Please help me on this. :(
From SQL Configuration Manager --> SQL Server Services --> SQL Server(SQLEXPRESS):
Binary Path will be: "c:\Program Files..\Binn\sqlservr.exe" -sSQLEXPRESS
So, try in CMD from path: ..\Binn> sqlservr.exe -sSQLEXPRESS. This should start the service.

Resources