Facing issue to connect from web job( in Azure app service) to SQL server (On Premises) - connection-string

On local it works fine. In Azure gives the error as Server not found or network specific instance not found.
We have 2 connection strings in app.config file.
One connection string is in <appsettings> section
Another connection string is under <Entityspaces> which is third party tool we are using.-
`
<Entityspaces>
<connectioninfo>
<conenctions>
<add name="" proivdermetadatekey=""> etc
</conenctions>
</connectioninfo>
</Entityspaces>
`
The connection string in apsetting is working fine. Connection string which is in another section entityspaces is giving issue

Related

What does localsql mean in connection string?

I am in the process of migrating sites from server A to server B, in the connection string, data source of some of the sites in server A, it says localsql but there is no ssms on server A because of which I am unable to find any databases on server A.
More interestingly, I have moved one site with localsql in the connection string to server B and the site is still working as expected.
I want to make sure there are no databases on server A and I want to know what exactly does localsql means in this context.
Any help would be appreciated.
Edit: Adding connection string
<appSettings>
<add key="ConnectionString" value="Data Source=localsql; Initial Catalog=dbname; User ID=id; Password=pw" />
</appSettings>
Probably the site hosted with LocalDB (named instance) which is light version of SQL Engine runs without a service. Usually, this can be identified by looking at connection string (which directly pointing the .mdf file) as it's different than regular SQL Server connection strings.
If it's localdb, these steps might be helpful to migrate the .mdf to SQL Server.

How to fix "Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net)"

I have a web application in visual studio 2017 .NET framework 4.7.1 with identity, that connects to azure sql server database. I am getting an error after submitting login form. The exception message is:
"Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username#servername). In addition, if both formats are used, the server names must match."
The error is only in the web server (azure app service). When I run it locally (localhost) it works fine.
I did what error message suggests but, it did´nt work. I searched about this but, none of the suggestions or solutions I found have worked.
If I remove login stuff, application is able to connect and works so, the problem seems to be the connection string I use to connect to identity tables.
I have tried this connection strings in web.config but none of them have worked:
1.
add name="DefaultConnection" connectionString="Server=tcp:myServer.database.windows.net,1433;Initial Catalog=myDatabase;Persist Security Info=False;User ID=myUser#myServer;Password=myPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False" providerName="System.Data.SqlClient"
2.
add name="DefaultConnection" connectionString="Data Source=myServer.database.windows.net;Initial Catalog=myDatabase;Integrated Security=False;User Id=myUser;Password=myPassword;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"
First, did you set the Allow access to Azrue Service ON?
Please check your Azrue SQL Database firewall settings on portal:
Second, get the correct connection string:
Others, please see: Troubleshooting connectivity issues with Microsoft Azure SQL Database.
Hope this can helps.

Cannot get classic ASP app to connect to database

We have an application which we are attempting to revive that was written in classic ASP in 2010. So far, I've done the following:
I created a Microsoft Server 2016 instance on Amazon EC2
I installed IIS Server
I created the website inside the IIS Manager, added/linked the files, and successfully ran the application on http://localhost
I installed SQL Server 2017 and imported the DB Backup (and successfully created the database)
I created a SQL Server user and tested that I can access the DB using the created database user
I enabled SQL Server Login Authentication and Windows Authentication Mode
I added the connection to IIS Manager.
I confirmed that web.config.xml has the proper information.
Im getting the following error:
2018-01-21 01:36:16 ::1 POST /intranet/process.asp |178|80004005|[Microsoft][ODBC_SQL_Server_Driver][DBNETLIB]SQL_Server_does_not_exist_or_access_denied. 80 - ::1
I noticed in the code theres a file that has a Session config for a database connection that doesnt look the same.
Im not sure what to do at this point. We need to figure out how to connect this database to the application
Heres my web.config.xml in the root:
<configuration>
<appSettings />
<connectionStrings>
<add connectionString="Server=server\SQLEXPRESS;Database=dbname;User ID=dbuser;Password=dbpass" name="SqlServer" />
</connectionStrings>
</configuration>
Here's my web.config.xml inside the intranet folder which is for an admin area:
<add name="WEB"
connectionString="Server=server\SQLEXPRESS;Database=dbname;User ID=dbuser;Password=dbpass"
providerName="System.Data.SqlClient" />
I noticed a file global.asa that has this:
Sub Session_OnStart
Session("ConnectString") = "Server=adifferentserver;Database=adifferentdatabase;UID=adifferentuser;PWD=adifferentpassword;Driver={SQL Server};"
This is my first time using ASP so you'd have to guide me for what other files you need.
The global.asa file in Classic ASP acts as an initialisation script it is commonplace to set long-running variables such as Application and Session variables there.
If this file contains a connection string variable then that is the value to change to your migrated database. At the moment process.asp is using Session("ConnectString") and ADODB is trying to locate adifferentserver using the SQL Server provider and failing. Once you correct the connection string using the required provider and server, database combination the page should work.
The other two values come from the web.config which was brought in with IIS 7.0 and above, it's designed for Microsoft .Net and Classic ASP does not know about connection strings configured inside it. The likelihood is there is another web application that uses ASP.Net that was making use of those connection strings.

Issue with website deployed to IIS and connecting to SQL Server 2012, getting network not found error

I have deployed a website to IIS and it is trying to access the database via the connection string.
My SQL Server and connection string is correct as I have tested it in the following ways:
My development environment streams data correctly
Connection to SQL Server is good as I could see from SQL Server Management Studio
Other pages of the website that are deployed are correct and only those pages that stream data is failing.
The problem is that it is only through the IIS website we have this error and when I run it from Visual Studio it is all right.
Here is the stack code I get:
Stack trace error
My connection string:
<add name="cnnSQLDB"
connectionString="server=**********;database=*********;Integrated Security=True;User ID=******;Password=******;"
providerName="System.Data.SqlClient"/>
Make sure that port 1433 is open on your firewall. That is the port SQL Server uses.
I was able to solve this issue based on hints provided here. I had to do the following changes:
Update the SQL connection string and set "Integrated security=false". In that way it will use the login credentials provided in the SQL connection string.
Create a new user as provided in the SQL connection string and GRANT the necessary accesses.
When I copied the databases from the production environment to a new environment the GRANT permissions for the user mentioned in the connection string was not updated.
But by checking the port status via the command 'sp_readerrorlog' gave me clues and led me to a solution. Some other links that helped me were: this and this

Web Service running locally won't connect to local database

I have a web service that's running locally via IIS. Using IE to navigate to it to test a specific service instantly returns 0 (default value returned by the stored procedure that gets called when something invalid is entered). However, if I change the connection string in web.config to connect to the server where the live database is hosted it works just fine. If I change the connection string to an invalid name for the server and try to test the service, it will load for about 15 seconds before returning 0, so I'm fairly certain the whole connection string is correct. I'm thinking it's something permission related with either SQL, IIS or both.
My connection string is:
<add name="LocalSQLServer" connectionString="Data Source=.\SQL_R2;Initial Catalog=localDBcopy;Persist Security Info=True;Trusted_Connection=Yes;Pooling=False" providerName="System.Data.SqlClient" />
When I connect it to the live server I replace Trusted_Connection with a name and password.
Why can't I connect to my local database? Or if I am connecting, why can't I run a stored procedure that's called through the web service? Any thoughts, or need any additional info?

Resources