Connect Microsoft Visual Studio 2010 to SQL Server 2008 R2 database - sql

I want to use my database in Visual Studio. I attach the database in SQL Server and when I want to run the project in Visual Studio 2010, I get this error:
http://i57.tinypic.com/2cz3rra.jpg
I enabled TCP/IP and disabled the firewall, and in SQL Server, remote connection is checked. My port is 1433 and everything is ok for Enable remote connection.
I connect to SQL Server by localhost .. and don't know what is my instance
Perhaps my project is not work good and error is for my project ..
I put my project link in first comment , any body can check it for errors ? This is very important for me !!

Check whether your id has access on the specified database(and server) or not. Also check whether you've enabled SQL server browser or not. Required services for the server in SQL configuration manager should be running.

Check your connection string or maybe your firewall is blocking the connection

Related

SQL Server Express - Connect from remote machine

I have two Win 7 64 bit machines.
On the first one I have installed SQL Server 2008 R2 Express and have no trouble connecting via Management Studio with Windows Auth and also via SQL Auth with a user I set up on the database.
On the second machine I am trying to connect to the database on machine 1 using Management Studio. I'm trying SQL Auth. I therefore obviously also can't connect to it via connection string in my .NET Code
I can ping the first machine from the second.
Things I have tried include the following:
On the machine the database is installed make sure the firewall is allowing connection on Port 1433
Made sure SQL Server service is running
Made sure SQL Server Browser service is running
Created an exception for sqlbrowser.exe in the firewall
Enabled TCP/IP Protocol through SQL Configuration manager
Allowed Remote connections in SQL Server Management Studio
The error I get 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
This is the connection string I use in code
Data Source=xxx.xxx.xxx.xxx\sqlexpress;Initial Catalog=dbName;User Id=myUser;Password=myPassword;
This can be caused by a number of reasons but I'm glad my suggestion about checking firewall ports (rather than just allowing a one-way exception for SQL Browser) led you to the answer: the firewall wasn't allowing the correct port # through.
If i remember correctly SQL Server disables remote connections by default.
Please check whether remote connections are enabled and enable them if not:
RMB on Server in Management Studio Object Explorer -> Properties -> Connections -> Allow remote connections...

Connecting to SQL Server Express - What is my server name?

I was just given a laptop to perform some development from a client and I am currently in the process of setting it up. Visual Studio 2010 is installed as well as SQL Server Management Studio 2008 R2. I'm trying to open SQL Server Management Studio to connect to the database but so far am not having much luck. I'm used typing in for a server name something like...
localhost
(local)
SQLEXPRESS
None of these are working.
So my question is: How can I tell what type of SQL Server installation and configuration I have on this machine, and how can I discover what server name I need to use in order to properly connect to it?
--Addition--------------------------------------------
I looked into the services as directed and found a few instances as indicated. SQLEXPRESS and MSSQLSERVER. I have tried to login with both of those options in these configurations...
SQLEXPRESS
MSSQLSERVER
computername\SQLEXPRESS
computername\MSSQLSERVER
.\SQLEXPRESS
.\MSSQLSERVER
None of these worked. I also altered the 'Log On As' property of the services from 'Network Service' to 'Local System' and tried them again. Still no success.
Instead of giving:
./SQLEXPRESS //in the Server Name
I put this:
.\SQLEXPRESS //which solved my problem
You should be able to see it in the Services panel. Look for a servicename like Sql Server (MSSQLSERVER). The name in the parentheses is your instance name.
If sql server is installed on your machine, you should check
Programs -> Microsoft SQL Server 20XX -> Configuration Tools -> SQL Server Configuration Manager -> SQL Server Services
You'll see "SQL Server (MSSQLSERVER)"
Programs -> Microsoft SQL Server 20XX -> Configuration Tools -> SQL Server Configuration Manager -> SQL Server Network Configuration -> Protocols for MSSQLSERVER -> TCP/IP
Make sure it's using port number 1433
If you want to see if the port is open and listening try this from your command prompt...
telnet 127.0.0.1 1433
And yes, SQL Express installs use localhost\SQLEXPRESS as the instance name by default.
Sometimes none of these would work for me. So I used to create a new web project in VS and select Authorization as "Individual User Accounts". I believe this work with some higher version of .NET Framework or something. But when you do this it will have your connection details. Mostly something like this
(LocalDb)\MSSQLLocalDB
by default -
you can also log in to sql express using server name as:
./SQLEXPRESS
or log in to sql server simply as
.
This was provided after installation of Sql Express 2019
Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;
So just use 'localhost\SQLEXPRESS' in server name and windows authentication worked for me.
Similar to what StuartLC was saying, my problem was not resolved until I enabled TCP/IP protocol under SQL Network Configuration>>Protocols for MSSQLSERVER in the SQL Server Configuration Manager dialogue box. After enabling this and a restart, my SSMS connected right away with just the instance name (no ~\MSSQLSERVER).
All of the following services should be running,for successful connectivity:
SQL Full test filter Daemon,
SQL server(SQLEXPRESS),
SQL Server Agent(SQLEXPRESS),
SQL Server Browser,
SQL server reporting service and
SQL Server VSS Writer

Cannot login to sql server 2008 R2 after rebooting server

I am using Windows-server-2008 with Microsoft SQL Server 2008.
And there are a lot of questions about this, but nothing on the internet solved it.
The problem is that i can't connect to the my SQL Server 2008 R2 after rebooting my server.
I placed some new memory in my server, and after rebooting my client/server application didn't work anymore because it cannot reach the database.
So i tried to get in SQL Server Management Studio (SSMS), and tried to loggin with Administrator and another user but both do not work.
When i logg in the following message is displayed:
Cannot connect to (local)
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)
(Microsoft SQL Server, Error: 2)
I Tried a lot of different things like:
Rebooting server
Try to start the server manually from Sql Server Configuration Manager
Named Pipes - Enabled
TCP/IP - Enabled
Tried to create an new system user or database user as described in the following article: Click Here
Can somebody please help me? I am really confused because i need to get this online. Otherwise i have to reinstall the database server but i do not have a back-up. (is there some folder with a back-up of the settings/tables/columns are stored and can be imported from reinstall?
I was having the exact same problem. net start mssqlserver was giving me the blurb about a failed login attempt. The problem was that I had recently changed the password for the administrator account, and the new password didn't get updated in services.
Here's how I fixed it:
First locate SQL Server from the list here:
Right click and select properties, and navigate to the Log On tab:
Then I typed the new password, and like magic I was able to start SQL Server right through the services manager.
I also did this for any other processes which were marked as "stopped" even though Startup Type was marked as "automatic" (namely, SQL Server Agent).
Is it a named instance or default? Also, is this a local instance? (I see the "(local)" but just wanted to make sure.)
Start the sql server services from services.msc and try to connect

Cannot connect to SQL server - client side issue

I might be the million'th person posting about this, but others' solutions haven't helped me. I have a database on Microsoft SQL Azure. I an trying to connect to it using the Visual Studio 2010's "Connect to Database" Tool.
From my Windows 7 machine, I can connect to it very easily. But from my Windows Server 2008R2 machine i am getting the classic 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)
All the posts around the web seem to be focussing on the problems on the server side, no one cares if the client goes rogue. :(
Thanks for the replies.
I have seen similar problems with VS2010 DB Tool and Windows Server so I would not suggest try using SSMS 2008 R2 (must be R2). Once you have download SSMS 2008 R2 and configured properly to work on Windows Server it sure will work. In most of the case you really need to open SSMS settings to get it workon on Windows Server.
Next a few points to check:
Verify that the telnet is working from your Windows Server Machine:
c:>telnet _your_sqlazure_database_name.database.windows.net 1433
Disable your real time security and the try again
Finally following the link to keep applying settings in your Windows Server and SSMS which are applicable and I am sure it will work:
http://www.mssqltips.com/sqlservertip/2340/resolving-could-not-open-a-connection-to-sql-server-errors/
One issue is that you need to connect via tcp, not named pipes (per your error message).
Are both servers behind the same firewall (e.g. the same external IP address)? The SQL Azure firewall needs to be configured to allow access from remote IP addresses.

Cant connect to SQL Server 2005 localhost

I've been trying to connect to SQL Server 2005 on my localhost and I can not connect...
Server name: (local)\SQLEXPRESS Authentication: Windows
Authentication
other Server name I have tried are
LOCALHOST\SQLEXPRESS
(local)\my local hostname
I get this error message:
Cannot connect to 127.0.0.1\SQLEXPRESS. 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.
SQL Server Browser is turned on in Services
any ideas?
(1)
You need to verify (not just guess) that the SQL Server service is running. You can do this by going to Start > Control Panel > Administrative Tools > Services, and checking that the service SQL Server (SQLEXPRESS) is running. If not, start it.
(2)
While you're in the services applet, also make sure that the service SQL Browser is started. If not, start it.
(3)
You need to make sure that SQL Server is allowed to use TCP/IP or named pipes. You can turn these on by opening the SQL Server Configuration Manager (found under Start > Programs > Microsoft SQL Server 2005 > Configuration Tools), and make sure that TCP/IP and Named Pipes are enabled. Here my instance name is different but you can see that both of these protocols are disabled (you'll want to check under Protocols for SQLEXPRESS):
(You'll need to restart the SQL Server service if you change these settings.)
(4)
While it is no longer used in current versions of SQL Server, you'll also want to check the Surface Area Configuration tool. This is also found under Start > Programs > Microsoft SQL Server 2005 > Configuration Tools. Click on "Surface Area Configuration for Services and Connections", then highlight SQLEXPRESS (again my local instance name is SQL2005 but pretend it's the same as yours), and under Database Engine > Remote Connections, enable "Local and remote connections" for the option "Using both TCP/IP and named pipes." In the screen shot below I only have TCP/IP enabled. If you change these settings, hit Apply, and again you'll need to restart SQL Server for the changes to take effect.
(This won't help your current problem but you may need to enable this if you want to connect to SQL Server from other machines, and it may also help future readers who are trying to connect to SQL Server 2005 remotely.)
(5)
It may also help to shut off Windows Firewall temporarily, in case you are blocking yourself somehow. (Control Panel > Windows Firewall)
(6)
Review SQL Server's error log. You can get to this file at a path something like:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\
(I don't have an Express instance handy so the path might be slightly different on your machine.)
Now, in that folder there will be a file called ERRORLOG... this is the most recent log file that was generated the last time SQL Server started. You can right-click this file and choose Open With... select notepad. You should see some lines like this:
2012-05... Authentication mode is MIXED....2012-05...
Server name is 'something\SQLEXPRESS'. This is an informational
message only. No user action is required....2012-05... Server
local connection provider is ready to accept connection on [
\.\pipe\SQLLocal\SQLEXPRESS ].2012-05... Server local
connection provider is ready to accept connection on [
\.\pipe\MSSQL$SQLEXPRESS\sql\query ].2012-05... Server is
listening on [ ::1 49164].2012-05... Server is listening
on [ 127.0.0.1 49164]....2012-05... SQL Server is now
ready for client connections. This is an informational message; no
user action is required.
Please tell us which of these lines you don't see, and what the second line says where I wrote "something\SQLEXPRESS".
If You have installed VS2008 then re-install sqlexpress2005 part once more or additionally you need to install that one then it will automatically fix its server name.
Make sure you have enabled the client protocols using the SQL Server Configuration Manager.