Connection string parameter cannot be null - asp.net-core

I have an MVC Core application that works on my machine, where SQLEXPRESS is not a named instance. When I deploy it to IIS 7.5 on a remote machine, where it is a named instance, without changing the connection string:
"Server=localhost;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
I get the following 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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
Then I correct the connection string for the nameD instance:
"Server=localhost.\SQLEXPRESS;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
I get the following error:
ArgumentNullException: Value cannot be null. Parameter name:
connectionString
In the stack trace on the developer error page, highlighted is the following line from Startup.cs:
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
How does changing only the connection string go from an expected connection exception to a null parameter exception?

Remeber that your configuration file is JSON which means certain characters need to be escaped, in this case it's the backslash. So from this answer you can see that you need to double up the backslash. For example:
"Server=localhost\\SQLEXPRESS;Database=QuickShare;......"

Related

Error after removing Connection from SSIS package

I am updating SSIS package to remove a connection to a web service that no longer exists.
I have removed the Tasks within the package that reference this connection, however when I delete the connection from the Connection Manager I get the following error:
The connection "Web Service Manager" is not found. This error is thrown by Connections collection when the specific connection element is not found.
When I search the code in the .xml file I find no reference to this connection and it is not used in the SSIS Logging. Where else can I remove this from as I found no trace of it anywhere.
I am using VS2008.

JSON Connection string configuration

In the app settings JSON file I am passing through a connection string which contains the name of my server
' .\SQL2017 '
I recieve the following warning in error list when entering the server name verbaitam as so in the connection string
'Invalid escape sequence'
When I then run the 'dotnet ef database update' command in the terminal I get the error
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not parse the JSON file.
When I take away the .\ from the connection string to remove the warning for 'Invalid escape sequence I get passed the error above and am then faced with the 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 conf
igured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I am sure that the rest of my connection string properties are correctly entered with no warnings but I am not sure how to format the server name in the connection string in a JSON format so that it can accept without any errors
Double the backslash to escape it:
.\\SQL2017

Error in BeginStartup CollaborationPlatform using ProvisionedApplicationPlatformSettings

I am trying to create an ApplicationEndpoint by first creating and establishing the CollaborationPlatform using ProvisionedApplicationPlatformSettings, when i execute:
ProvisionedApplicationPlatformSettings settings = new ProvisionedApplicationPlatformSettings("MYAPP", _appID);
_collabPlatform = new CollaborationPlatform(settings);
_collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);
in EndPlatformStartup method while executing collabPlatform.EndStartup(ar); i get an error
ProvisioningFailureException:
One or more values in the configured settings are invalid or unusable. Check inner exception and logs for more details.
The settings wrapper failed to initialize.
Unable to find the Sqld database: 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)
Found the Answer/Error,
i was trying to run the application from Windows 7 PC which apparently is not supported for Auto Provisioned Application , so now i build the application on my Win7 PC and then execute it on the Lync Server.

SqlException - The network path was not found

I'm running my code and getting this error. But what does it mean?
The network path was not found Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The network path was not found
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[Win32Exception (0x80004005): The network path was not found]
[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: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)]
This is probably related to your database connection string or something like that.
I just solved this exception right now. What was happening is that I was using a connection string intended to be used when debugging in a different machine (the server).
I commented the wrong connection string in Web.config and uncommented the right one. Now I'm back in business... this is something I forget to look at after sometime not working in a given solution. ;)
You will also get this exact error if attempting to access your remote/prod db from localhost and you've forgotten that this particular hosting company requires VPN logon in order to access the db (do i feel silly).
There may be some reasons like:
Wrong SQL connection string.
SQL Server in services is not running.
Distributed Transaction Coordinator service is not running.
First try to connect from SQL Server Management Studio to your Remote database. If it connects it means problem is at the code side or at Visual Studio side if you are using the one.
Check the connectionstring, if the problem persists, check these two services:
Distributed Transaction Coordinator service
SQL Server services.
Go in services.msc and search and start these two services.
The above answer works for the Exception:
[Win32Exception (0x80004005): The network path was not found]
Possibly also check the sessionState tag in Web.config
Believe it or not, some projects I've worked on will set a connection string here as well.
Setting this config to:
<sessionState mode="InProc" />
Fixed this issue in my case after checking all other connection strings were correct.
Same problem with me. I solved this by adding # before connection string (C# has a thing called 'String Literals') like so:
SqlConnection sconnection = new SqlConnection(#"Data Source=(Localdb)\v11.0; Initial Catalog=Mydatabase;Integrated Security=True");
sconnection.Open();
As others pointed out this could be more to do with the connectionstring config
Make sure,
user id and password are correct
Data Source is pointing to correct one , for example if you are using SQL express it will be .\SQLEXPRESS
Database is pointing to correct name of database
Hope that helps.
check your Connection String Properly.
Check that the connection is open.
String CS=ConfigurationManager.COnnectionStrings["DBCS"].connectionString;
if(!IsPostBack)
{enter code here
SqlConnection con = new SqlConnection(CS);
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblCountry", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
//Bind data
}
I recently had the same issue. It's more likely that your application can not connect to database server due to the network issues.
In my case I was connected to wrong WiFi.
At The Beginning, I faced the same error but with a different scenario.
I was having two connection strings, one for ado.net, and the other was for the EntityFramework, Both connections where correct. The problem specifically was within the edmx file of the EF, where I changed the ProviderManifestToken="2012" to ProviderManifestToken="2008" therefore, the application worked fine after that.
In my case, I had generated DbContext from an existing database. I had my connection string set in appSettings.json file; however, when I generated the class files by scaffolding the DbContext class it had incorrect connection string.
So make sure your connection string is proper in appSettings.json file as well as in DbContext file. This will solve your issue.
On my end, the problem was an unsuccessful connection to the VPN (while working from home). And yeah, the connectionString was using a context from remote server. Which resulted in the following error:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>The network path was not found</ExceptionMessage>
<ExceptionType>System.ComponentModel.Win32Exception</ExceptionType>
<StackTrace/>
</Error>
If you are using any db , please check connection string also
When I copied my solution from my pc to another one I had to change the connection string in web.config file.
Even if you have the same database name, you should do it for the server name as well.

how to remove security settings from a connection string in vb.net

hi i am trying to add data to the database that was created by some one but when am trying to insert or delete or update the exception is raising and entire project is not working properly and the error i am facing is
"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)"
so now what should i do to resolve this error and my connection string is written as
Dim CON As New SqlConnection("Integrated Security=SSPI;
Persist Security Info=False;Initial Catalog=DIGITALGAMES;
Data Source=TEJUS-PC\SQLEXPRESS")
is there any problem with my connection string ??
This error usually comes when database path is wrong i.e. system is enabe to locate the database
plz make apropriate modifications in
Data Source=TEJUS-PC\SQLEXPRESS
Dim CON As New SqlConnection("Integrated Security=SSPI;
Initial Catalog=DIGITALGAMES;Data Source=TEJUS-PC\SQLEXPRESS; User ID=yourusername; Password=yourpassword")
and
try this link
, with useful information about connection string
I think the server you are trying to access is either not in the network or you dont have windows authentication to that server.