C# SQL database access from another PC - c#

I am using C#, .NET Framework 4.5.2 and SQL Server 2014 Express edition (v12.0.2000). My requirement is to access this software from another PC means client system. Software is working fine in server PC not accessible in client PC.
Working until now
I followed the following two Microsoft official documents to make the database accessible on another PC:
https://learn.microsoft.com/en-us/sql/relational-databases/lesson-1-connecting-to-the-database-engine?view=sql-server-ver15
https://learn.microsoft.com/en-us/sql/relational-databases/lesson-2-connecting-from-another-computer?view=sql-server-ver15
To connect two PCs I followed this tutorial.
Result so far
I am able to access software in the network directory. I can run the .exe file of software on the client's PC. I can access the SQL Server in Microsoft SQL Server Management Studio on the client PC.
Can't do so far
The only thing that I can't do till now is my software on the client's PC is not able to access the database. It shows an error
Login failed for user
Connection string
I thought it should be a connection string error. I tried three different connection strings, let me write all here:
Data Source=.\\SQLEXPRESS;Database=dbposrpc;trusted_connection=true;
Data Source=.\\SQLEXPRESS;Initial Catalog=dbposrpc;User ID=sa;Password=12345678;
Data Source=tcp:DESKTOP-0DCQGE3,49172;Initial Catalog=dbposrpc;User ID=sa;Password=12345678;
SQLEXPRESS is the SQL Server instance name, DESKTOP-0DCQGE3 is the server PC name, 49172 is the TCP port that I selected.

For accessing a software from remote PC(Client's PC) you need to add inbound rules in Windows Defender Firewall with Advanced Security for this port the software is hosted on, then you also need to forward the port from your server PC.

The issue is resolved! All the steps I followed are perfect. You can say that if you want to connect to the client's PC using an ethernet connection. Follow the steps in question step by step. Focus on the connection string. Use the connection string of number 3. Let me write it again for clarification.
Data Source=tcp:DESKTOP-0DCQGE3,49172;Initial Catalog=dbposrpc;User ID=sa;Password=12345678;
Here SQLEXPRESS is the SQL Server instance name, DESKTOP-0DCQGE3 is the server PC name, 49172 is the TCP port that I selected as static.
How I resolved the issue?
I just cleared the solution, restarted the project again and everything worked fine for me.

Related

Login failed for user in SQL Server 2008 for Windows application

I have two PC (both have Win7). On PC "A" I have installed Microsoft SQL Server 2008 and developed a Windows application. On PC "A" my application is running well and there is no connectivity issue.
But when I run this application on PC "B" (connected with PC "B" through LAN and able to share any file) it shows error message login failed for user'....'.
I have already make some possible solution but can't solve it.. Need help
My connection string is:
Data Source=WIN7-PC\PRABHAT;Initial Catalog=plproject;User ID= win7-PC\Prabhat;MultipleActiveResultsets=true
Is there any problem?
The SQL Server error log contains addtional information about failed logins. Look there and find the code that maps to the table listed here: https://support.microsoft.com/en-us/kb/555332
One possible issue is that you are running as a machine account that doesn't exist on machine B. You need the Windows identity to flow from one machine to another and this is typically accomplished with a domain service account. If you want it to work from machine B, you need to access it with an account machine B is aware of. Supplying the User ID is typically for SQL Server authentication, not Windows authentication. You could try adding the password and see if that works.
Here is a breakdown of SQL Connection String syntax: https://www.connectionstrings.com/sql-server/
You need to enable TCP/IP for cross machine SQL SERVER access. Just follow below mentioned steps to ensure whether it is enable or disabled.
Click on window start menu.
Navigate to Microsoft SQL SERVER => Configuration Tool => SQL
Server 2008 Configuration Manager.
In Opened window Navigate to SQL SERVER Network Configuration =>
Protocols for <MSSQLSERVER> (Protocols for your SQL server
instance name)
Check Whether TCP/IP is enabled or not.

Do I have to install SQL Server if i use it in my application?

I made a library management system. I used SQL Server 2012 in my application, and now I want to share it. Do I also have to install SQL Server 2012 when I want to install my application on the other computers?
Note: my application is not on a server.
How have you used SQL Server in your application?
In general, as long as your application can connect to an instance of SQL Server, you should be ok. You can do that by having it running somewhere on the network, as long as the network will allow connections to the database server from the computers where your application is installed. In most cases, that just means you need to make sure the network security allows traffic on the ports that your install of SQL Server is using, and that the application has the correct connection string - that is, one that includes the machine name, address or IP to find the database server on the network.
If you used "localDB" as the SQL database type, you can probably just include it in a setup, and the dependencies should be installed by the setup.
If you used connect to a hosted versions of SQL (like SQL Server running as a service), you will have to install the SQL server and bring the database up, on the PC that will be running the app, or on a networked PC that this app can connect to.

Regarding local network connection string

I need some opinions and ideas on how to choose and use sql connection string? i do search fom sqlconnectionstring's website, but i tried for few types couldn't work with my network system. can pros out there help me please?
My condition is like below:
I got 1 computer for hosting and i installed sql2008 express server(microsoft sql management studio), and login as window authentication. (ip: 192.168.1.101)
With my created database was with out any security login id and password. (.MDF)
I got another computers work as client to connect and access the hosting computer which hosting the sql server. there ip had set to static (192.168.1.102, 192.168.1.103, 192.168.1.104)
i had tested this connection string but i failed to get connect
Data Source=192.168.1.101,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase
I did configure the firewall to allow the 1433 ports which is my sqlserver current using port. Checked sqlserver tcp:enabled, via:enabled, Namepipe:enabled, shareMemory:enabled. Setting of allowed computer remote-able.
So far these are what i configured, but still unable to connect, can anybody guide me?
Maybe because you're using a windows authentication. If you're connecting to SQL server using another computer, the login of that computer should be:
A part of a domain where the server is (i.e. [domain]\myusername).
It should be added to the SQL Server's Security\Login. Go to management studio, then in the object explorer under the server, go to the folder Security\Login. You should see a list of users under login. Your user (other computer's login) should be there.
Now, if you're not part of a domain, you should use a SQL server authentication. I haven't tried using windows authentication in two computers which is not part of a domain.

Can't connect to SQL Server database

I'm currently developing a web application using asp.net c#. I got a server where I today was
going to publish my website and its database. Its a server that runs Windows Server 2008 R2.
But I have one issue:
My website doesn't seem to get access to the database. If I run the website from another computer on my local network I can access the server's database, BUT I can't when I run the website from the same server where the database is. This is really weird. I hope someone can help.
I just get an error that says, it can't access the database.
The most weird of all is that I'm using the same connection string on both computers, but it still doesn't work. Are there maybe some sort of settings in Windows Server 2008?
Here is my connection string:
<add name="ConnectionString"
connectionString="Data Source=AXELS;Initial Catalog=Sailor;Persist Security Info=True;User ID=sa;Password=saab123"
providerName="System.Data.SqlClient" />
Since the connection works on one machine and not on another, I'd guess you have an issue with a firewall or similar - but it will be hard to tell until we see the actual error message. Until then, there are a few things you might want to do:
If it appears as if the connection has to time out before you get the error, it indicates a connectivity problem. Do you have a firewall between the two servers? Does the database server have a firewall that explicitly lets your machine (or internal) machines get through, but hasn't been setup to let the webserver get through? You have to make sure that port 1433 is open on the server.
Are there other sites on the webserver that can connect to the database?
If you have console access to the server, try to set up an ODBC from the server to the database - usually in Control Panel -> Data Sources (ODBC). If you set up a connection with the same DB Server, username and password and test the connection, you might get some pointers to what is wrong.
If the above doesn't provide you with an answer, I'd try to go through the steps described here:
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/
And if that fails, take a look at this - which is apparently only valid when you get SQL Network Interfaces, error: 26
http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
This is probably a permission problem.
You need to show us your connection string so we can see how exactly you try to connect to your database.
For example, if you are using Windows authentication, maybe your app runs under different accounts on both machines - and the account on the other computers has permission to access the database, but the account on the database server has not.
Have you checked the if the protocols you are using are enabled on the SQL Server e.g.
C:\Windows\System32\cliconfg.exe -- 64 bit version
C:\Windows\SysWOW64\cliconfg.exe -- 32 bit version
or check SQL Server Configuration Manager 'SQL Server Native Client *' tabs.
This is only applicable if you do not use Windows Authentication, else read the post about priviliges from Christian Specht - in this case I agree.
The fact that you can connect from another PC on the network means that all you database settings, user accounts and permissions are probably set up correct.
It seems there might be a issue with the way the server resolves localhost, as it will try to resolve the Data Source to localhost because AXELS = localhost on that machine.
Have a look at your hosts file and see if there's any funny pointers except for the default.
Located in C:\Windows\System32\drivers\etc
There should be an entry: 127.0.0.1 localhost

.Net connectivty

I have Oracle 10g installed on one computer and I have Visual Studio 2008 on other. I have both the systems on LAN. I am trying to connect to Oracle database from the second computer in Server Explorer. I am getting the following message
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
Also is the server name same as my second computer name
I am not really big on Oracle. Can somebody please tell me how to configure usernames and passwords with enough privelages to do administrative tasks
Lastly how would I achieve the same using connection string for creating OracleConnection assuming my database name is orcl, ip address is 192.168.0.5, server name is XYZ
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
That error message is telling you that you need to install the Oracle client on your client machine, i.e. the one with Visual Studio on it. See the documentation here.
There's a wealth of documentation out there describing how to configure and connect to Oracle databases. Here's Oracle's own Client Post-Installation steps, which include instructions on how to verify your installation.
Also is the server name same as my second computer name
Yes, the "server name" will be the name or IP address of the machine that your Oracle database is running on.
Lastly how would I achieve the same using connection string for creating OracleConnection assuming my database name is orcl, ip address is 192.168.0.5, server name is XYZ
This section of the documentation I've linked to above describes the different ways of connecting with a given set of credentials.

Categories

Resources