SQL Server Database Connection in VS 2010 - sql

I have completed my program in MVC in VS 2010. In the connection string I have the following
<add name="RacePaceDBContext"
connectionString="data source=XX.XXX.XX.XXX,1433;Initial Catalog=RacePaceDataNew;Persist Security Info=True;User ID=user;Password=password;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
Which connects to a SQL Server running on an EC2 instance on Amazon AWS.
The program runs fine and the connection works great. The program connects and creates/reads data etc.
However, I am not sure why when I try "Connect To Database" in the server explorer on the left, and fill in the same settings it just doesn't connect. Any ideas why this would be different? As want to be able to log in and see my tables, data etc without having to log onto AWS. The same is true when I use MySQL Workbench to try connect - it gives me an error telling me the server isn't accessible.

it might firewall issue, Please make sure your client can connect to xx.xxx.xx.xxxx:1433.
You can also refer this : https://forums.aws.amazon.com/thread.jspa?messageID=435146
Hope this helpful.

Related

Login failed for SQL Server user

I know this question has been asked before on here, but none of the solutions seem to have helped. I am migrating a database from one machine hosting SQL Server 2008 Express to another. Basically the exact same configuration. I backed up my database from Old Server to New Server. When I try to run my application, I'm told "Login failed for user 'sqluser'." I've compared the settings from Old Server and New Server and they are identical as far as I can tell. If it helps, here is my connection string:
<add name="RetailCrimeConnectionString" connectionString="Data Source=NewServer\SQLEXPRESS;Initial Catalog=RetailCrime;Persist Security Info=True;User ID=sqluser;Password=AwesomePassword"
providerName="System.Data.SqlClient" />
If I switch the connection string back to OldServer, my application is happy again.
The user sqluser is datareader and datawriter on RetailCrime -- just like he is on OldServer. The application is clearly connecting because the error changes to a connection error if I change the data source to something purposely incorrect. I've gone through the SQL instance settings and I think everything that needs to be enabled is enabled. I've even added a firewall exception (a step I didn't need to take on OldServer). And I have re-created the database and created a test one on NewServer with the same results.
Is there anything outside the normal fare of Google results that I may have missed? Let me know if there is any other info you need. I wasn't sure what other details to include.
Thanks!
I figured it out. It turns out that I set the server to only accept Windows authentication and not SQL Server accounts when I set it up. Once I set that in SMSS, the web application started accepting SQL login with no trouble. I came to this idea when I realized that I could connect by impersonating Windows accounts. Thanks for the ideas! Merry Christmas!
Have you created the SQL Login for sqluser and mapped it to the database user?
You only mention the database user in your question.
Try deleting "NewServer", and add "." instead. If it's not on the same machine, put IP address of NewServer in place of the ".", like "Data Source=10.10.46.15\SQLExpress". Like below:
<add name="RetailCrimeConnectionString"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RetailCrime;Persist Security Info=True;
User ID=sqluser;Password=AwesomePassword" providerName="System.Data.SqlClient" />
You also need to make sure your TCP/IP communication is enabled. This is for 2012 but step should be similar, See steps:
On the Start menu, click All Programs > Microsoft SQL Server 2012 >
Configuration Tools > SQL Server Configuration Manager.
Click SQL Server 2012 Services.
Expand the SQL Server 2012 Network Configuration node, and then
select Protocols for MSSQLServer (SQL Instance Name).
Right-click TCP/IP, and then click Enable.
Select SQL Server 2012 Services in the tree.
Right-click SQL Server (SQL Instance Name), and then click Restart.
Update:
Last thing to try, maybe:
Go to Start > Microsoft SQL Sever 2012 folder > Configuration Tools > Open SQL Server Configuration Manager
Make sure everything on the list in SQL Server Services is not Stopped. And make sure the start Mode is set to Automatic, not manual.

How to launch the SQL Server service in browser

I am new to SQL Server. I am doing the offline sync using SQL Server and sqlite DB. For that I followed the below tutorial SQL Server Installation. In this tutorial I am stuck on how to open the localhost service. When I run the service (localhost/AuroraSyncService.svc) in browser it shows empty.
For this I created the database AuroraSyncCn in my SQL Server Management Studio and created the new website in my IIS (internet information security).
MY coneection Strings:
<connectionStrings>
<add name="AuroraSyncCn" connectionString="Data Source=(local);Initial Catalog=SQLite-Sync.com;User ID=sa;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
here i tried connectionString="localhost/myservicefolde/aurorasyncservice.asmx;
Somebody help to solve this one.
From what I see your connection string should contain your database name (Initial Catalog=AuroraSyncCn).
If it's SQLExpress, instance name should probably be the same as the one mentioned by vasin1987 (server/serverinstance).
But from what I remember from ASP.NET, 'localhost' as Data Source should also be just fine.
Can you please show/write what you have in login window in MS SQL (Server name is what interest us the most):

Cannot connect to database from wpf outside development machine

I am currently creating a data drivien wpf application, and everything works perfectly as a charm on my development computer (the computer I used to create the program). Also, when I move the app from the Release directory and copy to my local machine, it works perfectly. But on the other hand, when my application reaches other users, it stops connecting to databases completely.
I don't get how this is as I have my connection string set properly, which is:
<connectionStrings>
<add name="MyConnectionStrint"
connectionString="Data Source=MyServerIP\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Which is an XML Config file located in the root directory. As soon as the program is given to someone else, it stops functioning completely; no data is received or sent.
Could this be because of something like, they need MS SQL Server or something for it to connect to my remote database? I even tried connecting to the database using SQL Server Management Studio, which fails to work on other PCS, but for some reason works on mine and no one else's. This is a problem as this program is meant to be distributed to at least 15 people. Any Ideas as to what Is causing this?
Any help would be appreciated, thanks.
Is the database server on your development machine ?
If so, then you have to enable the tcp/ip configuration in your SQL Server Configuration Manager.
If that's not enabled then your server will not be accessible outside of the machine on which it resides.

Entity Exception : the underlying provider failed to open with Timeout expired

OK, I'm stumped. I am trying to create a .NET Winforms app to talk to a database via Entity Framework. I originally created a ASP.NET MVC3 app (with a seperate DAL layer) that can talk to the database after initially failing. SO the first time that it tries to open the connection, it times out. If I then hit F5 in the browser, it connects fine!
I referenced this DAL in my Winforms app.
I can connect to the database via SQL Auth in SQL Management Studio fine.
I can create the ADO.NET Data classes in VS2010 (it connects, gets the tables and stores the connection string in the app.config).
However, once I run the Winforms app, I am unable to connect. I get the mentioned exception with an InnerException of "Timeout expired."
I copied the connection string from the web.config to the app.config.
The SQL database is hosted on my Windows Home Server called SERVER. I am in a Workgroup (no Domain). I uses SERVER\SQLEXPRESS in Management Studio and VS to successfully connect to it.
Things I've tried:
Disable the firewall on the client machine.
Enabled DTC on the server and added msdtc.exe to the exclusion list on the server.
Made sure Named Pipes in enabled on the SQL server instance.
Tried different SQL users.
Tried different ways of constructing the connection in C#.
Generated a new ADO.NET Data class local to my WinForms project (not referencing the DAL). VS connects fine, reads the tables, generates the code. But the running app causes a "Timeout Expired" SqlException.
So running the app is unsuccessful in connecting. When I watch the app in ProcessExplorer I can see an entry in the TCP window when it tries to Connect on remote port 4845 with a SYN_SENT message. Not sure if that's right.
I've google'd and bing'd this for the last few days, I've read all the articles and replies here on Stackoverflow that mention this exception, but I have hit a wall.
This is the ConnectionString that VS generated after reading the DB:
<add name="LLDBEntities" connectionString="metadata=res://*/LLDB.csdl|res://*/LLDB.ssdl|res://*/LLDB.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER\SQLEXPRESS;initial catalog=LLDB;persist security info=True;user id=sa;password=sapwd;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Any help appreciated, even any hints on how to figure out what's happening.
Your connection string looks more like a connection string to an SQL Server, rather than SQL Express.
Have a look at this for a connection string to SQL Express: SQL Server Express connection string for Entity Framework Code First
Ok, solved.
I noticed that it would actually connect on the second attempt with the same app and connection. At that point I found this link: http://kromey.us/2011/06/microsoft-sql-server-2008-times-out-on-first-connection-attempt-447.html
So I opened the firewall port listed under IPAll Dynamic Port in SQL Server Configuration Manager on the TCP/IP Properties for the instance and now it all works fine. I still don't know why it would get through on the second attempt....

Cannot connect to local SQL Server with Management Studio

I'm having an issue with SQL Server, I have 2005 installed on my desktop as well as having SQL Server Management Studio installed..
I've checked and can see "SQL Server (SQLEXPRESS)" started in services.
I've tried to connect to "Local" and "SQLEXPRESS" but both fail to connect.
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) (.Net
SqlClient Data Provider)
Anything else I need to do to connect to it??
UPDATE
I seem to be getting a little further along now. Ive managed to connect to my server with SQL Server Management (FYI .\SQLEXPRESS did the trick) but now im having a issue with my connection string in my web.config
Ive im going to connect to this local sql server using windows authentication how do i need to structure it??
Something like this?
<add name="BensBoxing" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=BritBoxing_Alpha;Integrated Security=False;User Instance=True" providerName="System.Data.SqlClient"/>
This produces a error about
Login failed for user ''.
Check the sql log in the LOG directory of your instance - see if anything is going on there. You'll need to stop the service to open the log - or restart and you can read the old one - named with .1 on the end.
With the error you're getting, you need to enable TCP/IP or Named pipes for named connections. Shared memory connection should work, but you seem to not be using that. Are you trying to connect through SSMS?
In my log I see entries like this...
Server local connection provider is ready to accept connection on [\\.\pipe\mssql$sqlexpress\sql\query ]
As the comments said, .\SQLEXPRESS should work. Also worstationName\SQLEXPRESS will work.
Same as matt said. The "SQL Server(SQLEXPRESS)" was stopped. Enabled it by opening Control Panel > Administrative Tools > Services, right-clicking on the "SQL Server(SQLEXPRESS)" service and selecting "Start" from the available options.
Could connect fine after that.
I was having this problem on a Windows 7 (64 bit) after a power outage. The SQLEXPRESS service was not started even though is status was set to 'Automatic' and the mahine had been rebooted several times. Had to start the service manually.
Try to see, if the service "SQL Server (MSSQLSERVER)" it's started, this solved my problem.
Open Sql server 2014 Configuration Manager.
Click Sql server services and start the sql server service if it is stopped
Then click Check SQL server Network Configuration for TCP/IP Enabled
then restart the sql server management studio (SSMS)
and connect your local database engine