How to connect to SQL Server 2000 from .net 4 - sql-server

Here's my connection string...
Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;
Here's the 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)
I can connect fine with Enterprise Manager. Also I have upgraded the SQL Server to Serivce Pack 4.
Any ideas what the issue might be?

I'd suggest testing your connection string using a .UDL file. I've answered a similar question here. After creating your connection, you can rename the extension of the file to .txt, open it and then copy and paste the working connection string in.

string connectionString=#"Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;";
SqlConnection connection=new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("Select * From Table",connection);
SqlDataReader reader= command.ExecuteReader();
GridView1.DataSource=reader;
GridView1.DataBind();
Use this.... this may help you?

Related

TableAdapter.Fill raises "A Network-Related or Instance-Specific Error"

I'm currently developing a program using Visual Studio 2010 and SQL Server 2008 R2.
I'm currently facing a problem while connecting to a SQL Server. For starters, I have a station with IP 192.168.15.101 establishing a connection to a SQL Server with IP 192.168.0.11.
This station can successfully ping the server, and I can also connect to SQL Server located in the server from SQL Server Management Studio. The code below runs smoothly as well :
.extQuery = *SQL Query Here*
Try
If InternalSupport.RefreshConnection(False, GlobalVar.connectionString, GlobalVar.Server, False) Then
.command = New SqlCommand(.extQuery, .connect)
.reader = .command.ExecuteReader
While .reader.Read
*Some Code Here*
End While
.reader.Close()
.command.Dispose()
.connect.Close()
Catch ex As Exception
*Error Handling Here*
End Try
However, the problem lies when I tried to refill my Table Adapter for VS Built in Data Source. Whenever I call the code below :
Me.TEMPORARY_DUETableAdapter.Fill(Me.DsAscendPending.TEMPORARY_DUE)
It raises 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
What I have tried are :
Allow Remote Connection on SQL Server on Server side.
Set Connection String Dynamically from code.
Disabling windows firewall and antivirus.
Make sure all the ports and IP in SQL Server are open
Connect SQL Server from SQL Server Management Studio located on remote location, and it connects perfectly.
Any help on this error is greatly appreciated. Thanks!
SOLUTION
I've found the solution. The problem lies in my Connection String. I was using server computer name as Data Source instead of IP.
Below is my previous Connection String :
connectionString="Data Source=MAIL-SERVER;Initial Catalog=MG_CreativeLab;Persist Security Info=False;User ID=sa;Password=#adminmedan123#"
It will allow connection from the same IP Segment, while rejecting connection from other segments
Here's the correct connection string :
connectionString="Data Source=192.168.0.11;Initial Catalog=MG_CreativeLab;Persist Security Info=False;User ID=sa;Password=#adminmedan123#"
Thank you for the response!
I've found the solution. The problem lies in my Connection String. I was using server computer name as Data Source instead of IP.
Below is my previous Connection String :
connectionString="Data Source=MAIL-SERVER;Initial Catalog=MG_CreativeLab;Persist Security Info=False;User ID=sa;Password=#adminmedan123#"
It will allow connection from the same IP Segment, while rejecting connection from other segments
Here's the correct connection string :
connectionString="Data Source=192.168.0.11;Initial Catalog=MG_CreativeLab;Persist Security Info=False;User ID=sa;Password=#adminmedan123#"
Thank you for the response!

SQL Connection String failing to connect SQL Instance

I am attempting to debug an application, but when I run it I get the following error 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I've opened up the 1433 port and double-checked it's open and reachable from my current location. I've also enabled TCP/IP remote connections and can connect remotely using SQL Server Studio Manager.
The connection string I'm using is:
Data Source=xx.xx.xxx.xx, 1433;Network Library=DBMSSOCN;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;User ID=KnightOwlGentleshaw; Password=xxxxxx
I'm 90%sure there's something wrong with the connection string but I'm not sure what?
If you are not sure about the Connection string, use a udl file for testing:
Create a new text file.
Change the extension to .udl (e.g. 1.txt to 1.udl)
Go to the Connection tab
Insert your credentials (Servername\instance , user name + password / Windows security etc)
Check the Allow saving password check box
Click on Test Connection and get a success message.
Click on OK (this will close the form)
Open the 1.udl file in a text editor - It will contain the connection string that was used for the successful connection
Now you can compare the connection strings / use the one you now that works...
Good luck!
Try this code
Data Source=xx.xx.xxx.xx;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;

SQL Server Express connection string error

Trying to figure out the correct connection string for a SQL Server Express database. Trying to publish my app to IIS and test before publishing to my hosting site.
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 started here and also used connectionstrings.com. I also started reading the deploy asp.net app using SQL Server Compact article here
Using this connection string
Data Source=.\\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True
I get the above error
This connection string
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf"
providerName="System.Data.SqlClient" />`
throws a trust level error. I've changed to medium and full and still get one of the two errors.
I've tried a variation of a few different strings with no luck.
Thanks
Please verify that SQL Service is started in services.msc and use the complete instance with the hostname ej: HOSTNAME\SQLEXPRESS
The file extension indicates that this is not a SQL Server Express database, so you must use:
Data Source=<Full path to file>
or
Data Source=|DataDirectory|Guestbook.sdf

error connecting to sql server compact file in VS2012

I use following connection string for connecting to my SQL Server Compact database (.SDF file) in a VS 2012 (.NET 4) Win form app:
SqlConnection SQLConnection = new SqlConnection("Data Source=d:\\mydb.sdf;");
but I get following error, what is going wrong?
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)
Use SqlCeConnection instead of SqlConnection.

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

In my project I do have DB in sql server 2005 and its working in local. but when I try to connect remote sql server 2008 R2 by using the credentials I got the following error.
System.Data.SqlClient.SqlException was unhandled by user code
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)"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=20
LineNumber=0
Number=53
Server=""
State=0
And I enabled the following in remote server
1) Started SQL server, sql browser service using sql server configuration manager.
2) added the sql server, browser exe in to firewall allowed program list.
3) restarted sql server and browser.
4) enabled TCP/IP, Shared memory, Named pipes in SQL server configuration manager
5) I enabled the remote connection for this DB in database property
6) and the connection string in following manner
SqlConn = new SqlConnection(#"Data Source=IP address;Initial Catalog=DbName;
User ID=ID;Password=pwd ");
also while taking the properties of Db using the view current connection property in remote it shows service is unavailable for entries like DBname, authentication mode, network protocol etc...
if any one have this issue before please help.
thanks & regards,
Tharadas.
along with the options enabled in the question I solved the issue by doing the following changes.
1) in Sql connection string added the sql port number(1533 or 1433).
2) add exception for port number in firewall.
Thanks & regards
Tharadas k.p

Resources