Error in Connecting to SQL Server from a web form - c#

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) ....

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 = ""

Connection string is not valid in reporting services SQL Server 2012

I am getting following error every time I try to register new user in Reporting Services Form Authentication. I don't know how to get away from it. I am following the steps from here.
Error message is:
An error occurred while attempting to add the account. 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)
Any solution?
Your connection string is not correct. Test it in another tool other than your program if you have doubt. First thing to check is if the server is actually accessible as the message states The server was not found or was not accessible.

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.

Can't access MYSQL server from c# forms application - error in connection string

myConnection = new SqlConnection("user id=champion3_test;" +
"password=test;server=10.168.1.58;" +
"Trusted_Connection=true;" +
"database=champion3_sabdb; " +
"connection timeout=30");
This code gives the error:
Thrown: "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)" (System.Data.SqlClient.SqlException) Exception Message = "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)", Exception Type = "System.Data.SqlClient.SqlException", Exception WinRT Data = ""
Here are some screenshots that might help with debugging of my server's settings:
http://imgur.com/a/PeRby
I know that 'champion3_test' is a valid user id
'test' is a valid password for champion3_test
the database name is 'champion3_sabdb'
SQL server isn't MySQL. If you are using MySQL, download the MySQL .NET Connector and use their connection class, MySqlConnection.
To learn how to use the MySQL Connector, you can start here.
You can download the MySql Connector for .Net here.
Once you've installed the driver, you can connect using the MySql Connector classes:
string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
MySqlConnection conn = new MySqlConnection(connStr);

Not able to see the SQL Server 2008 instance in services

I have a named instance of SQL Server 2008 called TEST on my local machine but I am not able to see the services related to that instance in Services.msc. All I can see is service named SQL Server (MSSQLSERVER). And when I try to connect to this instance using my C# application using the connection string :
Server=localhost\\TEST;Database=TESTDB;Trusted_Connection=True;
it throws me this exception :
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)
Kindly help

Categories