Seriate SqlContext Error. Failed on step 'connecting' - sql-server

I'm new to Nodejs and I have to implement some changes in an small project. It runs over Sql Server using seriate module. I throws this error...
Seriate SqlContext Error. Failed on step 'connecting'.Failed to connect to 127.0.0.1:undefined in 15000ms
when executing a getPlainContext() with the following config object:
{
"user": "node",
"password": "node",
"server": "127.0.0.1\\SQLEXPRESS",
"database": "lms-db-dev"
}
I already tryied using (local)\\SQLEXPRESS which I'm using on my Web.config file connection string:
Server=(local)\SQLEXPRESS;Database=lms-db-dev;user id=node; password=node
I'm wondering why it tryies to connect to 127.0.0.1:undefined and how can I fix this.

The problem is that the driver doesn't works with instance name, but Ip/port only. So I removed the instance name and added the port property on the config object with my local server's port, following this answer. My config object becames this:
"db": {
"user": "node",
"password": "node",
"server": "127.0.0.1",
"database": "lms-db-dev",
"port": "52519"
}

I had to turn on the SQL Server Browser service to get Seriate to work with the instance name.

Related

Cannot use container name to connect to SQL Server container in containerized Blazor app

I am trying to learn Docker Compose by creating a simple Todo List app with Blazor. It's a simple solution with just the Blazor app and SQL Server containers. I'm having problems connecting the app to the db.
However, every attempt to query the db results in:
Microsoft.Data.SqlClient.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: TCP Provider, error: 40 - Could not open a connection to SQL Server: Could not open a connection to SQL Server)
Here's my current docker-compose.yml:
version: '3.4'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: mssql
environment:
- SA_PASSWORD=Str0ngP#ssword
- ACCEPT_EULA=Y
ports:
- 1433:1433
expose:
- 1433
blazor_playground:
image: blazor-playground
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
depends_on:
- mssql
Now I supply a connection string in Program.cs:
const string CONNECTION_STRING = "Server=mssql,1433; Database=playground; User Id=sa;Password=Str0ngP#ssword; Integrated Security=false; TrustServerCertificate=True;";
builder.Services.AddDbContextFactory<TodoContext>(
options => options.UseSqlServer(CONNECTION_STRING)
);
I can confirm that I can connect to SQL Server with SSMS. It's there that I create the playground database and TodoItems table if they didn't persist.
Additionally, running just the SQL Server container causes the Blazor app to run fine locally (switching mssql with localhost in the conn string).
According to the Docker Compose networking docs, I should just be able to use the container_name as the server name, but it's still not working.
I had high hopes that info in here would help, but didn't: How to connect to SQL Server docker container from another container?
What can I do to fix this or further troubleshoot?
UPDATE
Here's the result of docker inspect blazorserverplayground_default:
$ docker inspect blazorserverplayground_default
[
{
"Name": "blazorserverplayground_default",
"Id": "bd8d031d4fc7f2d49fa934e0f1beb1f633284ff60a3c0048740f9d367cb15b6e",
"Created": "2023-01-25T22:51:53.990730099Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.24.0.0/16",
"Gateway": "172.24.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"9de8742b7f96e0b55109e2141a54652d1403edeb9b3efbafeba8e8c69d45318a": {
"Name": "blazorserverplayground-blazor_playground-1",
"EndpointID": "925b031756389ee29fdc037613ea4eb2115891d658e772d25ee4d6dfc1e4d800",
"MacAddress": "02:42:ac:18:00:03",
"IPv4Address": "172.24.0.3/16",
"IPv6Address": ""
},
"e185c2886c551ad3ca00fe915a59a061ff46878f2dbc55d5924d4b94ad2879d7": {
"Name": "mssql",
"EndpointID": "93480cc94dbf21ea08d0123fefccbd7ba30b4e3077b7fef6758552147d6c30c1",
"MacAddress": "02:42:ac:18:00:02",
"IPv4Address": "172.24.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "blazorserverplayground",
"com.docker.compose.version": "2.15.1"
}
}
]
Looks like the SQL Server container is named properly. Not sure why the DNS won't resolve correctly.

Vite Proxy Using Http2 returns "unable to verify the first certificate"

I am trying to setup a development environment using HTTP2 requests with Vite and a local backend. I proxy requests between client and server both running on localhost. The server is configured with a generated certificate using Mkcert (https://github.com/FiloSottile/mkcert).
Configuration:
To configure the certificate I run the following steps:
mkcert.exe -pkcs12 "test" "127.0.0.1" "localhost"
Configure the backend to use the generated cert
mkcert.exe -install
Use the following vite configuration:
server: {
https: {
pfx: fs.readFileSync(`./cert/test.pfx`),
passphrase: "some-phrase",
},
proxy: {
"/api": {
target: `https://localhost:15000`,
changeOrigin: true,
secure: true,
},
},
},
Currently this configuration works on Mac but fails on Windows. Both use the same backend and certificates but on Windows the proxy will fail with: "unable to verify the first certificate". In the browser the certificate chain is a correctly validated.
Troubleshooting:
When I run openssl s_client -showcerts -connect localhost:15000 -servername localhost the query results in "unable to verify the first certificate" as well basically indicating that the mkcert Root CA isn't properly found.
Using openssl s_client -showcerts -CAfile "C:\Users\SomeUser\AppData\Local\mkcert\rootCA.pem" -connect localhost:15000 -servername localhost the certificates will be correctly validated. This should indicate that the proxy lacks a reference to the rootCA of Mkcert.
I have tried supplying the rootCA using the following script in package.json:
"dev": "cross-env NODE_EXTRA_CA_CERTS=\"C:\\Users\\SomeUser\\AppData\\Local\\mkcert\\rootCA.pem\" && vite",
This doesn't help however and the proxy still fails with the same error. I assume Mac and Windows work differently when supplying the CA root certs to Node or fails silently?
Anyway, how can this solved? I have been thinking about supplying the full cert chain in a cert that I supply to Vite, but this shouldn't be needed if Node could just reference the RootCA correctly.

Angular 7 - Can we remove Port number

I am using Angular with ASP.Net Web application. When i am using ng build App build and run on URL without port number. But if i run app using ng serve its open with a port number.
i know that i can change port number and host name on angular.json file,
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ng-app:build",
"port": 4200,
"host": "myapp.withAspweb.local"
},
Is that possible to remove port number from URL.
ng server - myapp.withAspweb.local:4200
ng build - myapp.withAspweb.local
There is no such thing as "no port". The default http port is 80, so just try
"port": 80
You can always configure the port to be 80 in your angular.json-file, as you already mention.
In regards to changing your hostname, I'd suggest you set it to 0.0.0.0 (any incoming host) and modify your hosts file (located in C:\Windows\System32\drivers\etc\hosts) to provide the desired hostname.

Why my launchSettings.json settings get ignored?

I just got IdentityServer to run on my Windows 10 from qickstart VS.Net 2019 project. In my launchSettings.json file, I configured it to run HTTPS on port 5008, instead of the default 5001, as shown bellow:
{
"profiles": {
"SelfHost": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5008"
}
}
}
The problem is, when I start IdentityServer using SelfHost profile, it still starts on HTTPS:5001 and my settings are always get ignored, as the console screen shows below:
…
[14:16:04 Information] Microsoft.Hosting.Lifetime
Now listening on: http://localhost:5000
[14:16:04 Information] Microsoft.Hosting.Lifetime
Now listening on: https://localhost:5001
…
What am I doing wrong here? Isn't launchSetting.json the place you can change those settings?
To develop locally with ASP.NET Core under HTTPS, SSL, and Self-Signed Certs, follow these steps:
Install the certificate on the machine, by running in cmd:
dotnet dev-certs https --trust
Copy localhost Certificate thumbprint
Then run in cmd for each URL:
"C:\Program Files (x86)\IIS Express\IisExpressAdminCmd.exe" setupSslUrl -url:https://my.domain.name:<port> -CertHash:<Certificate thumbprint>
I have these instruction with snapshots here

Could not proxy request /pusher/auth from localhost:3000 to http://localhost:5000 (ECONNREFUSED)

I am trying to create a chat app using reactJS and pusher, i am getting this error-
Could not proxy request /pusher/auth from localhost:3000 to
http://localhost:5000 (ECONNREFUSED)
in package.json file i have set proxy as-
"proxy": "http://localhost:5000"
and my localhost is defined as 127.0.0.1 in /etc/hosts file.
I have also checked for the port availability using netstat, but these all seems to be correct. Can anybody help?
I had a same problem in my React App and I fixed it by just adding "/" after the port number in package.json file (so now it's: "proxy": "http://localhost:5000/")
I faced a similar issue but in Mac machine. I changed localhost to 127.0.0.1 and that worked for me.
For windows:
"proxy": {
"/auth/google": {
"target": "localhost:5000"
}
}
For Mac:
"proxy": {
"/auth/google": {
"target": "http://127.0.0.1:5000"
}
}
In your server package.json add --ignore client to your "start" or "server" scripts. So it would look like this:
"scripts": {
"start": "node index.js",
"server": "nodemon index.js --ignore client"
}
In server directory
npm install --save http-proxy-middleware
then create a file with this name : setupProxy.js
in src directory of client react folder
then add the following
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(proxy("/api/**", { // https://github.com/chimurai/http-proxy-middleware
target: "http://localhost:5000",
secure: false
}));
};
In proxy configuration make sure you are matching any path
with double ** not only *
Note: you are not going to require this proxy anywhere else
just like that
Note: remove any other proxy settings in package.json
For more check this reference
I think You have not start your Back end server. Try start both Back end and Front end server concurrently. Just simply run npm start in both back end and front end.
In your node module include
{
...
"proxy": "http://127.0.0.1:5000"
}
Where the ... simply means you should append the proxy ip to it.
Also, if you are using axios, doing axios.post('api/users') works and not axios.post('/api/users')
For those who are using Docker, if your docker-compose.yml looks like:
services:
app:
...
depends_on:
- api
ports:
- 3000:xxxx
...
api:
...
ports:
- 5000:xxxx
...
Then we should set the proxy URL to
"proxy": "http://host.docker.internal:5000"
In package.json file just add "/" after the port number and it should work fine.
"proxy": "http://localhost:5000/"
I have similar issue.
The problem was that server was listening on ipv6 ::1 address
and the proxy was connecting to ipv4 127.0.0.1
I changed both addresses from localhost to 127.0.0.1
Use
"proxy":"http://localhost:PORT_NUMBER/"
in package.json
and in axios backend call route like
use axios.get("api/user/getinfo") instead of axios.get("/api/user/getinfo");
None of these answers were helping me despite everyone's effort. Finally, thankfully, I found this github discussion where someone said use node server.js to start the server. This WORKED. Before I was using nodemon server.js and npm start. I've no idea why those commands weren't able to connect to my proxy at http://127.0.0.1:5000 but node server.js could.
Cheers
I think Server not working properly, you should run client and server concurrently for that add following procedures in package.json file
1) Install concurrently
npm install concurrently --save
2) configure client and server
"server": "nodemon server.js",
"client": "npm start --prefix client"
3) configure concurrently
"dev": "concurrently "npm run server" "npm run client""
if you are not using concurrently at your server side then simply run each front-end and back-end separately such that server side should run first and client side last.
Changing localhost to [::1] solved my problem.
Taken from here https://forum.vuejs.org/t/proxy-error-with-vue-config-js-and-axios/110632/4?u=mahmoodvcs
This has something to do with default settings of create-react-app.
I found a solution from Github Issue. Read the response by danielmahon on 15 Mar 2018
"proxy": {
"/api": {
"target": "https://localhost:5002",
"secure": false
}
},
If you can't connect to localhost on port 5000 via telnet (you can download and use PuttY if you don't have telnet installed), then that means that server isn't running.
If you're using a Windows machine, go to your package.json for the server that is running on port 5000 and change this line:
"start": "./node_modules/.bin/concurrently \"./node_modules/.bin/nodemon\" \"npm run client\"",
To this:
"start": "./node_modules/.bin/concurrently \"npm run server\" \"npm run client\"",
Watch your build messages and you should see something similar to the following:
[0] 🌎 ==> API Server now listening on PORT 5000!
[1] Starting the development server...
[1]
[1] Compiled successfully!
[1]
[1] You can now view chat app in the browser.
[1]
[1] Local: http://localhost:3000/
[1] On Your Network: http://192.168.1.118:3000/
[1]
[1] Note that the development build is not optimized.
[1] To create a production build, use yarn build.
My issue was trying to run my react project with docker containers open.
Change the ports or shut down the containers.
In my case the problem was that I have been accessing the PORT by the wrong name, i had it PORT instead of SERVER_PORT which was my correct environment variable name. So this problem means that there is a something wrong in your code, in my case the port on which the server should be running was undefined.
Proxy error: Could not proxy request /signup from localhost:3000 to http://localhost:8282/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
I got the same issue and I just solved it by only restart both of the server, you need to run both of the server running.
Thanks me ltr:)
If you are using axios, then follow this.
Using proxy might not work sometimes. There is a standard way to solve this issue.
For that we need to configure our axios before sending requests. axios has a method to set the baseURL create() Create a new file http.js in your src folder.
import axios from 'axios'
const http = axios.create({
baseURL: "http://localhost:5000"
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
export default http
Now insted of using using axios for sending request, use this
import axios from "../../http";
happy coding!
In my case, I changed port number from 5000 to 7000, while reactjs was still fetching on localhost 5000, after I changed everything worked perfect
ReactJs FETCH HOOK:
const { data, loading, error } = useFetch(
"http://localhost:7000/api/hotels/countByCity?cities=Arusha,Dodoma,Mwanza,Dar-es-salaam"
);
NodeJS server port:
const PORT = process.env.PORT || 7000;
I recently got this error when waiting for a response from my rest API function which does not return any.
so you either need to change the API implementation and send something back to the client or just don't wait for a response if you are not returning any.

Resources