MVC connection string: An error occured while processing your request - sql

I'm new to Windows server and have no idea how to create connection string on my IIS for my website. I've already created my MVC website and it's working fine on my localhost.
But when I run it on IIS server in Plesk Panel, it gives an error:
An error occured while processing your request.
This happens whenever I try to make request to DB. When I want to sign up I face the error above.
Here's my connection string that I'm using:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=.MSSQLSERVER2012;Initial Catalog=myDatabase;user=myDbUser;pwd=myDbPass; Integrated Security=True"
providerName="System.Data.SqlClient" />

In Data Source="Enter your server Name Here" If you still got an error share your error screen.

Related

SQL Server (Linked Server)

My database is from a linked server and I have a problem with my connection string in ASP.NET (web.config) it says that :
Database schema could not be retrieved for this connection. Please make sure the connection settings are correct and that the database is online. Cannot open database "AA" requested by the login. The login failed. Login failed for user 'sa' at DataObjectSupport(423,6)
I try to use this connection string.
<connectionStrings>
<add name="localconnection" connectionString="Data Source=SERVERNAME;Persist Security Info=True;Initial Catalog=database; uid=sa; Password=password; " providerName="System.Data.SqlClient"/>
</connectionStrings>

Uploading Website with Visual Basic Inbuilt .mdf Database in VB.Net (Aspx)

I am creating a website to have a database with it (i.e. Upload the website with the App_Data folder that has Database.mdf in it).
But it cannot connect the attached database using (web.config file)
It works on localhost but it does not work when uploaded, can anyone help me?
**
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</connectionStrings>
<appSettings>
<add key="ConnectionString" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</appSettings>
**
The attribute 'Data Source' in ConnectionString notifies SQL Server instance you are using. On Localhost, it will work fine because you have a actual SQL service running there. But when you upload the Site to web server, you must have a SQL server instance running there.
To achieve that, you have to upload your database to server, then you will get server username, password. Now change the connectionstring according to that in web.config and your application will work fine. No need to keep .mdf in App_Data folder.

ConnectionStrings error 26 - SQL / Visual Studio

I have added a database file (NORTHWND.MDF) to my application using Visual Studio 2010 built-in functionality. Database is in the App_Data folder.
It is running fine in local-host. But when I publish it and upload it to server it gives 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)
My connection string is that automatically generated by visual studio in my web.config:
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
My host support SQL Express, but it dont work..
I read that once everything is upped on the host do not have to use "AttachDbFilename" .. but I have not figured out how to fix it .. Could someone tell me the correct connection string?
Thanks in advance.
You Sholud Use this connection String if you have your db attached to SQL management Studio
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
User ID=myDomain\myUsername;Password=myPassword;
Reference:
https://www.connectionstrings.com/sql-server/

Failed login for user

I'm developing a website for sharepoint using asp.net, it is connected to a database. In visual studio server explorer, the database is accessible using a new sql user I created. I granted sysadmin permissions to that user. However, when I deploy the site and run it, it gives me this error 'login failed for user'.
The sql server is configured to allow mixed authentications. I restarted the server, I played with the user permissions but nothing ever changed.
The connection string I got it from server explorer which I'm sure it is correct:
Data Source=servertest;Initial Catalog=qDB;User ID=me2;Password=***********"
What should I do? I've tried every possible solution I found on google and I ended up here.
Try like this by editing your connection string:-
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
I too had same scenario this worked for me
<connectionStrings>
<add name="connectionstring" connectionString="Data Source=XYZ\SHAREPOINT;Initial Catalog=DBName;Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
You can Use connection string like this
<appSettings>
<add key="KhadamatConnectionString"
value="Server=[copy name from Your ServerName of SSMS];Database=AcaService;uid=admin;pwd=mypass;" />
</appSettings>
or
<connectionStrings>
<add name="KhadamatConnectionString" connectionString="Data Source=[copy name from Your ServerName of SSMS];Initial Catalog=AcaService;User ID=admin;Password=mypass;" providerName="System.Data.SqlClient"/>
</connectionStrings>

provider: SQL Network Interfaces, error: 25 - Connection string is not valid

I developed this application on my local computer using VS2012 and SQL 2008R2. I am trying to move it onto production server. It is a virtual server with 2012 SQL Server. I checked all the properties for remote connection and everything is enabled. The application opens with the login screen and once I enter the username and password (this was created on my computer using WSAT. Now 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: 25 - Connection string is not valid)
This is what I have in web.config:
<connectionStrings>
<remove name="LocalSqlServer" />
<add connectionString="Server=\\events;Database=Digital Signage;Integrated Security=true" name="DSConnectionString" />
<add connectionString="data source=\\events;Integrated Security=SSPI;AttachDBFilename=c:\\DS\aspnetdb.mdf;User Instance=true" name="LocalSqlServer" providerName="System.Data.SqlClient" />
Not entirely sure, but some points which may help you troubleshoot:
You can use a resource like this to help you generate the appropriate connection string
I am not sure that Server=\\events sounds entirely right - you should perhaps replace this with the actual SQL instance name here when deploying remotely (either <machine name> or <machine name>\<instance name> for a named instance)
You probably don't need to explicitly state the port which SQL Server is listening on (if it's still the default 1433), but something to keep in mind
Do you have anywhere that you explicitly reference the connection string LocalSqlServer in your code? If so, have you changed that to reference the connection string DSConnectionString before building and deploying? (NB. It may be better to just keep the connection string entry but change the value of the connection string to what you need for the SQL 2012 instance, rather than creating a new connection string entry but I'm not sure about your specific use case)