Solved

Moving c# programs and SQL to a new server

Posted on 2016-08-31
12
89 Views
Last Modified: 2016-09-06
We are moving our current programs to a new server.  I need to test them before they go live.  This particular program is web based using c#. When I use Visual Studio and step through my code everything works like it should.  When I publish the program and run it I get the following 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...

I am thinking it is a permissions problem but I am not familiar enough to know where to start.  Can someone help me with this?

BTW- I looked at the 'Connections' for this sql server and the 'Allow remote connections to this server' is checked.
0
Comment
Question by:huerita37
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 41779011
Can you access the SQL server remotely via ssms?
0
 
LVL 1

Accepted Solution

by:
Danlo earned 250 total points
ID: 41779016
There are two places you need to set permissions in SQL Server (Management Studio).

First, you need to be sure there is a Login [Server -> Security -> Login] that matches the login the C# applications are trying to connect with.

Second, you need to add a 'User' to the database that the application connects to, using the login account you created above.

[Server -> Database -> Security -> Users]

Make sure the User has at least dbDataReader rights (for Read-only access), and also dbDataWriter rights, for the ability to modify data in the database.

HTH,
Danlo
0
 
LVL 1

Expert Comment

by:Danlo
ID: 41779020
In addition, make sure that the SQL Server instance is set to allow both SQL Server authentication and Windows Authentication, unless the C# app is impersonating a user.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41779100
Did you update the connection string to point to the new server?
0
 
LVL 11

Assisted Solution

by:Nakul Vachhrajani
Nakul Vachhrajani earned 250 total points
ID: 41779266
Going to basics - The first task is that your request must "reach" the server.

If you use SSMS on your workstation (not where the SQL Server service is hosted), can you connect to your SQL Server instance? If this is a new server that IT built, do ask IT to check the firewall. Newer operating systems block traffic and hence it is possible that you are unable to reach the SQL Server itself.

Next, check if accces to the server using TCP/IP is enabled (it is disabled by default). You can check this in the SQL Server Configuration Manager on the server (which is the same place you would go to in order to manage your SQL Server service).

If the above two points check out, then the instance level configurations of allowing remote connections and setting permissions come into play.
0
 

Author Comment

by:huerita37
ID: 41781779
I'm testing the above responses.  I am not at work on Thursdays so I am looking at it now.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:huerita37
ID: 41782022
Here is my testing so far:

I am able to access the DB even if I am not on the server itself.  If I run my program locally I can access data on the SQL Server.

There is a login and user that matches what I use to connect to the SQL Server.

I am pointing to the new SQL server because I can select/update to the new server when I am testing locally.
0
 

Author Comment

by:huerita37
ID: 41782108
Is there a permission on the webserver that I need to set?  When I run the program from the new webserver but point to the old SQL server I get the same error.
0
 
LVL 11

Expert Comment

by:Nakul Vachhrajani
ID: 41782159
I believe it is the firewall on the webserver which may be blocking outbound traffic.
1
 
LVL 1

Expert Comment

by:Danlo
ID: 41782280
I believe it is the firewall on the webserver which may be blocking outbound traffic.

Nakul Vachhrajani may be correct. here.  Standard SQL Server traffic port is 1433.

From a command line window on your web server, run 'netstat -aon | more' so check if that port is being listened to/for.

If the server is not indicating that it is listening for that port, you may need to enable the TCP/IP protocols inside SQL Server Configuration Manager.

If it IS listening for that port already, it's most likely being blocked by a firewall setting.  Make sure you have SQL port open in Windows Firewall for Domain and/or Private networks.
0
 

Author Comment

by:huerita37
ID: 41786649
I have not been given permissions to get to this server.  I can only access the DB tables.  I have talked to our DB admin about everything that has been said here.  He checked the connection and it was not set to a local connection.

Thank you everyone for all of your help.
0
 

Author Closing Comment

by:huerita37
ID: 41786653
I appreciate all of your help.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now