I installed my VB application on client PC which in local network, but application can not reach database with err:40
Some details to describe the problem:
My connection string as it is in config file:
"PioneerHRSystem.My.MySettings.CON1"
connectionString="Data Source=SERVER\SQL2014ENT;Initial Catalog=MYDATABASE;Integrated Security=True"
providerName="System.Data.SqlClient" />
I checked the configuration in server to make sure about setting like:
Instance name=SERVER\SQL2014ENT
SQL server and windows Authentication= Selected
TCP = enabled
Port (1433) = opened in both of them (server & PC)
Allow remote connection to this server = selected
Ping testing for IP=Received
Server restarted
Also I played with connection string by adding IP & Port in like:
PioneerHRSystem.My.MySettings.PPECON1"
connection String="Data Source=192.168.8.3\SERVER\SQL2014ENT;Initial Catalog=MYDATABASE;Integrated Security=True"
providerName="System.Data.SqlClient" />
PioneerHRSystem.My.MySettings.PPECON1"
connectionString="Data Source=192.168.8.3\SERVER\SQL2014ENT1433;Initial Catalog=MYDATABASE;Integrated Security=True"
providerName="System.Data.SqlClient" />
PioneerHRSystem.My.MySettings.PPECON1"
connectionString="Data Source=192.168.8.3\SQL2014ENT,1433;Initial Catalog=MYDATABASE;Integrated Security=True"
providerName="System.Data.SqlClient" />
PioneerHRSystem.My.MySettings.PPECON1"
connectionString="Data Source=192.168.8.3\SQL2014ENT;Initial Catalog=MYDATABASE;Integrated Security=True"
providerName="System.Data.SqlClient" />
But still I get error:40 could not open connection to SQL Server
NOTE: all modification was done through the config file (as I know it should work if correct) am I correct?
UPDATE:
The Complete message is:
************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.
For example:
<configuration> <system.windows.forms jitDebugging="true" /> </configuration>
Related
Initially, my project (running on localhost with SQL Server Express) had a connection string to the database Test1:
<connectionStrings>
<add name="TestContext"
connectionString="data source=.\SQLEXPRESS; Integrated Security=SSPI; Initial Catalog=Test1; User Instance=true"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
Now, I want the same project uses a different database: Test2.
So I've changed the "Initial Catalog" in the connection string to Test2.
But, to my surprise, when I execute the application, the Test1 database is still the one to be used.
What am I doing wrong?
I've already try to stop/start the IIS and delete the "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" folder with no success.
I am creating a website, but in the database I use windows authentication.
I know that you use this for SQL authentication
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
user id=sa;password=P#ssw0rd"
providerName="System.Data.SqlClient" />
</connectionStrings>
How do I modify this to work with windows authentication?
Replace the username and password with Integrated Security=SSPI;
So the connection string should be
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
For connecting to a sql server database via Windows authentication basically needs which server you want to connect , what is your database name , Integrated Security info and provider name.
Basically this works:
<connectionStrings>
<add name="MyConnectionString"
connectionString="data source=ServerName;
Initial Catalog=DatabaseName;Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Setting Integrated Security field true means basically you want to reach database via Windows authentication, if you set this field false Windows authentication will not work.
It is also working different according which provider you are using.
SqlClient both Integrated Security=true; or IntegratedSecurity=SSPI; is working.
OleDb it is Integrated Security=SSPI;
Odbc it is Trusted_Connection=yes;
OracleClient it is Integrated Security=yes;
Integrated Security=true throws an exception when used with the OleDb provider.
For the correct solution after many hours:
Open the configuration file
Change the connection string with the following
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
Change the YOUR_SERVER_NAME with your current server name and save
Open the IIS Manager
Find the name of the application pool that the website or web application is using
Right-click and choose Advanced settings
From Advanced settings under Process Model change the Identity to Custom account and add your Server Admin details, please see the attached images:
Hope this will help.
This is shorter and works
<connectionStrings>
<add name="DBConnection"
connectionString="data source=SERVER\INSTANCE;
Initial Catalog=MyDB;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Persist Security Info not needed
If anyone comes looking for asp.net core, we will have to add connection string in appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=SQLServer\\Instance;Database=MYDB;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Source: add windows authentication sql server connection string
I have setup a local installation of DNN7 using a database residing in another machine (sqlserver 2008).
I've tried to copy all the filesystem to a production server but keep the connection string the same, so use the exact same database.
I get the message
"The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty."
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
The application pool and IIS settings are the same in both machines. Any ideas of what am I missing?
You are missing following section in web.config
<connectionStrings>
<!-- Connection String for SQL Server 2005/2008 Express -->
<!-- Connection String for SQL Server 2005/2008
<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />
-->
</connectionStrings>
The problem had to do with the role membership provider.
For some reason the AspNetSqlMembershipProvider provider falls back at the default one which is in the machine.config (insided the .NET folder).
In dev environments with an SQLEXpress instance running, the machine.config has a connection string named 'LocalSqlServer' which points to the SQLExpress. That's why it worked in my dev environment.
The server on the other hand, doesn't have SQLExpress, so no LocalSqlServer connectionstring exists in the machine.config and therefore the error pops up.
The workaround I found in DNN forums is to add these lines inside the section of the web.config
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=dbserver;Integrated Security=false;Initial Catalog=dbName;User ID=dbUser;Password=dbPass" providerName="System.Data.SqlClient" />
I'm creating a simple ASP.NET MVC 4 application using Entity Framework and code-first. With SQL Server Express 2012, everything works fine when using Windows Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
However, when using the following for SQL Server Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=False; User Id=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
I receive an error:
"Login failed for user 'mysa'" ProviderIncompatibleException.
Am I missing something?
Is it possible that your *.mdf file is not attached to sql server instance?
Try attaching the myDb.mdf file to your database with SQL Management Studio and the change the connection string to
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; Category=myDb;Integrated Security=False; User=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
and don't forget to give the appropriate rights to your user
I created an MVC3 Internet application and changed the default connection string to work with
.\SQLSERVER instead of the default .\SQLEXPRESS and get 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: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)
I tried creating an empty MVC3 application as well, which has no connection string by default and added mine with the same result.
The SQLSERVER instance is running and I can connect to it from management studio using windows authentication. Any connection string that I use gives same error, I cannot figure it out:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLSERVER;" providerName="System.Data.SqlClient" />
</connectionStrings>
To connect to your local default instance (i.e. SQLSERVER service name), for Data Source=..., use one of the following:
127.0.0.1
localhost
(local)
.
EDIT
Your connection string should resemble this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Checkout the different connection strings you can use with SQL Server. For example if you have a SQL Server installed on your local machine you could use the following connection string:
Data Source=127.0.0.1;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Obviously you will need to adjust the name of the database, the username and password to connect to.
If you want to use Windows Authentication to connect to the server:
Data Source=127.0.0.1;Initial Catalog=myDataBase;Integrated Security=SSPI;
Your connection string needs to look something like this:
<add name="NameOfConnection" connectionString="Data Source=localhost;Initial Catalog=OMSCING;Trusted_Connection=Yes" providerName="System.Data.SqlClient" />
Where you can replace localhost with a hostname or leave it like that if the server's local.
Perhaps I had to mention that I was using EF with code first approach, but the problems was due to the name of the connection string which should be the same name as your Context which you derive from DbContext, e.g.:
<connectionStrings>
<remove name="ApplicationServices"/>
<add name="MyContext"
connectionString="data source=localhost; Initial Catalog=CoolCars;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
as well make sure you remove the default machine.config connection string which is for .\SQLEXPRESS