SQL connection not connecting to Claims database - c#

I cant connect to my claims database on a copy of a github project. I keep getting:
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)
I'm able to connect using the same connection string in another project, but not this one. Are there any files besides appsettings.json I need to change?
appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=xxx.206;Database=test_MIM; User ID = me; Password= notpassword;Trusted_Connection=False;MultipleActiveResultSets=true"
},

Related

how to use pm> Update-Database command?

i am trying to run the command Update-Database in package manager console. the following errors appears.
this is the connection string I tried using
"ConnectionStrings": { "sqlserver": "nvlohuqx:YXGg4spm1KAvIidbFufyLMt9HeCZMZDD#surus.db.elephantsql.com:5432/nvlohuqx" }
it showed this error
“Format Of The Initialization String Does Not Conform To Specification
Starting At Index X”
and then after I changed the format for the connection string to the following:
"sqlserver": "Server=surus.db.elephantsql.com;Database=nvlohuqx;User Id=nvlohuqx;Password=YXGg4spm1KAvIidbFufyLMt9HeCZMZDD;"
I get this new 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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL
Server)"
I recommend use Ip instead of domain on Server = ""

Can't connect local mdf database file

I build a simple CRUD app in C# and used server based database file (.mdf) in my Project. My connection string is like this:
public string connectionString { get; set; } = $"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"{AppDomain.CurrentDomain.BaseDirectory}Passwords.mdf\";Integrated Security=True";
In my computer application works fine just I want, but after send to my friend, he got error that can't connect or find SQL database. Error text 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 we download SQL server express 2019 for him (I use 2017 by the way) and after that, still he get the same error. I dont understand what is the problem. Any succession?

Local db error. A network-related or instance-specific error occurred while establishing a connection to SQL Server

I have web site running Visual Studio 2015 with local db,everything works great. But production server is not working.
connection string is
"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;".
i tried connection string
"Data Source = (LocalDB)\V11.00; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;".
Full error is :
Server Error in '/' Application.
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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
)
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.Data.SqlClient.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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
How can I solve the problem?
Since you changed environments, for e.g. local laptop to prod server
For production, check and update your data directory.
"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;".
to debug Hard code the directory path, if it works you can set you env variable for =|DataDirectory|\SeedDb.mdf
Then check server/roles for the dir under security (right click folder)
Your init string should point to the instance name of your production SQL server.
data source=SQLSERVER\INSTANCE;initial catalog=databaseName
SQL Server can be installed as a default instance. In that case instance name should be omitted.

Error in Connecting to SQL Server from a web form

I want to connect SQL Server in my webform program.
I use this command :
Connection = new SqlConnection("server=sharmi-PC/MSSQL2012;database=PeopleDb;trusted_connection=true");
but I get an error :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in PeopleManagement.BusinessLogic.dll
Additional information: 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)
My server name in SQL Server is
sharmi-PC\MSSQL2012
If you say yourself that your server name is
sharmi-PC\MSSQL2012
then why aren't you using that in your connection??
Use this:
Connection = new SqlConnection(#"server=sharmi-PC\MSSQL2012;database=PeopleDb;trusted_connection=true");
Use the proper notation for server/instance name - a backslash (as in sharmi-PC\MSSQL2012) - not a forward slash as you used (sharmi-PC/MSSQL2012) ....

Remote Connection Error in Asp.net

I am trying to make a registration page, that stores Username, password,and email,
but
When ever i try to Connect database using this string,
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RConnectionString"].ConnectionString);
conn.Open();
Following Error appears:
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)
I searched everywhere, but it didn't helped me..
The issue starts from web.config and the connection string that is located at RConnectionString according to the code line you give.
Locate this string and fix it to been able to connect to your database.
And some examples here: Setting up connection string in ASP.NET to SQL SERVER

Categories