Cannot connect to database from wpf outside development machine - sql

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.

Related

SQL Server trusted connection has wrong user in IIS, but SSMS is OK

I am using VS 2012, connecting to SQL Server 2008 host using windows credentials. I can connect fine from Management Studio, but when I run a web application (IIS 7.5 windows 7 ASP.NET 4.0 integrated) and my application tries to connect, I get this:
Login failed for user 'MyDomain\MyMachineName$'.
For some reason IIS App pool using Network Identity is not using MyUserName but my machine name instead. My connection string is:
<connectionStrings>
<clear />
<add name="Assignment"
connectionString="Data Source=a.b.c.d;Initial Catalog=My_Db;Trusted_Connection=true;Max Pool Size=200;Pooling=True;" />
</connectionStrings>
I should mention this is a new (to me) computer. I looked in credential manager and there is nothing there. Any ideas why IIS and my web app using the wrong thing?
IIS is actually doing exactly what it was designed to do when you run your app pool under the Network Service identity.
Using the Network Service account in a domain environment has a great
benefit. Worker process running as Network Service access the network
as the machine account. Machine accounts are generated when a machine
is joined to a domain. They look like this:
<domainname>\<machinename>$,
For example: mydomain\machine1$
The nice thing about this is that network resources
like file shares or SQL Server databases can be ACLed to allow this
machine account access.
The quote above is from the following documentation...
http://www.iis.net/learn/manage/configuring-security/application-pool-identities
Hopefully this answers the question of why it isn't working the way you expect.
As far as how to make it work the way you want, I think this article should answer that question, and if not, some basic google searching should come up with quite a bit of information on how to properly configure your environment for what you're trying to do.
https://gilesey.wordpress.com/2013/05/11/allowing-iis-7-5-applications-to-communicate-to-sql-server-via-windows-authentication/

sql server 2008 Anonymous login failure

First, let me say that I have spent the last two days researching this problem on this site as well as others, obviously without result. So on to the problem:
I have moved a website and database from my old 32 bit machine to a new 64 bit machine. Both are configured as follows:
Windows 7 Ultimate N
SQL Server 2008 R2
IIS 7.5
The database uses SQL Server Authentication
In the web.config file:
Database connection string:
<add name="ConnectionString" connectionString="Data Source=PEYCO\;Initial Catalog=CatalogName;Integrated Security=True;Connect Timeout=0" providerName="System.Data.SqlClient"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
IIS has Anonymous Authentication enabled. The website on both machines are configured the same. I can access the website from both machines without problem. However, when I go to pages that require the user to be logged in, the error occurs.
In both cases, the database and iis are located on the same machine. I am able to access tables and stored procedures from the management console without problems.
The original machine works correctly, but the new one gives the above error when running code-behind that accesses the database. Logins work correctly. I have probably tried every combination of settings possible, and still the problem persists.
Any help would be most appreciated.
Thanks in advance.
PS: I should also add that I have tried this connection string" <add name="ConnectionString" connectionString="Data Source=PEYCO;Initial Catalog=Name;Integrated Security=false;uid=sa;pwd=MyPwd;Connect Timeout=0;Trusted_Connection=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient;"/>
The application on IIS runs under application pool. This application pool is run under some user account, default is IIS APPPOOL\DEFAULTAPPPOOL. This user (or other if you have set it otherwise) is trying to connect to the database but has no permissions to do so. Therefore you receive an error.
You need to allow this user to connect to SQL Server.
Turns out that the problem was router related. There are multiple computers running and the port was being routed to the wrong computer. (Banging head against wall...)

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.

SQL Server Database Connection in VS 2010

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.

WPF application with local database

I'm making a WPF application with a local database,
I made the database with SQL server management studio, then I linked a .edmx file to the database I made.
Now if i wanna run my program on another PC i don't have that database anymore so it kinda crashes.
Can I copy my database file (.mdf) in my Debug folder and change my App.Config so it takes that database?
Becouse I wanna copy my program to a computer that dosn't have SQL server Management studio installed. Is that posible?
My App.Config looks like this atm:
<connectionStrings>
<add name="PRCEntities" connectionString="metadata=res://*/PRC.csdl|res://*/PRC.ssdl|res://*/PRC.msl;provider=System.Data.SqlClient;provider connection string="Data Source=DESKTOP-BERNARD\SQLEXPRESS;Initial Catalog=PRC;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>
Thx
You can copy the mdf but:
The target machine has to have SQL Server installed
You'll have to attach the mdf file
You'll need to change the connection string, either let the user that installs the application enter it or change the machine name to localhost but you might run into machines that have named instances and no default instance.