In PC1 I created a C# application wins forms which uses local SQL server database then I deployed my application to .exe file using Visual studio. Then I installed the exe file into same PC (PC1) and I works fine and can connect to SQL database using the following connection string:
SqlConnection con = new SqlConnection("Data Source=local; Initial Catalog=mydb; Integrated Security=True");
The problem is: when I went to another PC (PC2) I installed SQL server and I manually attached the same database (mydb) and then installed my application but it gives me the following error:
However, when I change the name of PC2 same as PC1 the application can connect and it works well.It means if I want to install my application in different PC then I have to name that PC same name as the original PC which I created my C# in (PC1).
why is this error happening? I mean why do I have to set other PCs to have the same name as the original PC (PC1). Please help me how to fix this eror. Thank you
You don't have to have the same name on different PCs to have a C# program connected to a SQL server. One thing I would like to point out, maybe you are aware maybe you are not. If you install the database on EACH machine they programs won't share the data (again, this might sound silly but just in case).
To the error itself, if you installed SQL Server on machine PC2 go to Services and double check that the SQL Server INSTANCE is the same as the one you set up on your connection string. You don't have to even have the same database name it could be totally different on each machine, the important thing there is to have the correct connection string (you should have the connection string as a configuration that you can easily change from a .conf file.
Just double check on PC2 that the server is working as expected (check services and Event Viewer for any errors that might popup) you can also try instead of local 127.0.0.1
You need to activate Sql Server and Windows authentication in your sql server and change your connection string from integrated security to user/password authentication.
Data Source needs to be changed either to IP or to the name of the server
Related
I have made a C# application MySql Database attached I am going to use the Application on a different Computer. According to my Logic. The Mysql database is running on the localhost server of my first PC and I think that the localhost of the other PC will be different. So,My application Won't connect to the server - It's my Idea which may be wrong.
I have the following Questions :-
1.
How do I make a Mysql local server that will even work on another PC.
2.
Do I have to Install MySql on other PC ? If yes How can i include mysql setup in the Setup Wizard of my app.
3.
Do I have to make changes In the Code (Connection or anything).
Please Give any extra suggestion if you have about this.
You do not need to install mySQL on the computer that will have the app. that defeats the purpose of having a SQL Server
You will only need to change the connection string so instead of connecting to Localhost or 127.0.0.1 you will use the ip address of the machine that has the server installed. Connection Strings
I suggest you do some reading about networking, design patterns, and SQL or you risk building a very insecure application.
I have created a simple login application using the C#.net. I have some basic sql database(I use SSMS). There is name, email and password. I want my application to be usable from more devices (so I can't use localdb). Everything works fine on my pc but when I move to another, where is not installed ssms it shows error 26 - Error Locating Server/Instance Specified. I don't know how exactly to run my C# application without SQL Server Management Studio installed on client machine
I have researched for a weeks so I enable tcp/ip (from sql server manager), also add new inbound rules for tcp(1433) and udp(1434) ports in windows firewall. After that I allow remote connection and add sql server in windows firewall. Also I've tried to install SSMS on client machine but nothing
here are my conncetion strings
this one I tried to solve my problem
Data Source=xxxxxxxxxxxx;Initial Catalog=xxxxxxxxxxx;Integrated Security=SSPI
the other one is my main connection string
Data Source=xxxxxxxxxxxxxxxxxxxxxxx;Initial Catalog=xxxxxxxxxxxxxx;Integrated
Integrated Security = True
The application works fine on my computer, I've installed Visual Studio 2017 and SQL Server Management studio, but when I move to another computer it doesn't work.
Thanks to everyone in advance!!
SSMS is just a Database Management Tool, the actual Database would by SQLExpress or similar. So on your remote host you need to install the latter and set it up correctly in you application to use to appropiate connectionstring to it.
Schema compare your tables from VS and your ready to go.
https://www.microsoft.com/en-us/sql-server/sql-server-editions-express
https://www.mssqltips.com/sqlservertip/5528/installing-sql-server-2017-express/
You dont need to install sql or sql managemment studio in pc where you running your application, but just as your error said "Error Locating Server/Instance Specified", the server where you want to connect, is not accesible, thats means you should open your ports in pc where your sql server is hosted, and also, put your public ip following with that port in your server name in conectionstring, like Data Source=yourserver_IP:8076; tip: make sure your app pc and server pc are in same network.
The reason it works on the same machine is most likely is is that when you go through another machine the connection has to go through a firewall that is blocking access to SQL Server. The default port that SQL Server uses is 1433 and unless you change it on the host machine when you connect from another machine that is the port that is use to connect and you don't have to specify the port. When you connect on the same machine that SQL Server is installed the firewall does not prevent you from connecting. Port 1433 is used for the default instance (The first installed instance on the machine).
I'm using Visual Studio 2015 and I just created a Windows Forms application with a SQL Server database. I finished the program and tried to run the application on the other computer but it didn't run. I also tried to install .Net Framework v4.0 and SQL Server Express on that computer and also put the database in path C:\ so that the SqlConnection path on my computer to another computer will be the same.
The code is like this:
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
string connection = #"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Database1.mdf;Integrated Security=True";
But I got an error that is the database I placed in path C:\ is not writable whatsoever. I want to know what I can do in order to run the application.
You must install SQL Express on the computer/server where you want to have the database and then attach the MDF file.
Important:
- Remember to open port 1433 in the Windows Firewall.
- If you are going to use SQL Server authentication, you must create and / or activate the user with the desired password.
- To connect you can use the IP of the computer/server, preceded by the instance of sql express. Example: YourIP\SQLExpress
Good luck!
you need to create sharing server for database and after this, you can access your DB to anywhere and any computer
Thanks
So much misunderstanding and misinformation around LocalDB.
While it was being developed, your application was using an edition of SQL Server called LocalDB. This is a low admin lightweight edition that lets you reference the MDF file directly (contrary to some comments here)
When you deploy your app you decide whether you want to stick with LocalDB or upgrade to a more scaleable edition of SQL Server.
In your case, I suggest you stick with LocalDB
There's some background here and a link to a video if you have time
LocalDB deployment on client PC
https://blogs.msdn.microsoft.com/sqlexpress/2011/07/12/introducing-localdb-an-improved-sql-express/
Now if you really want to an answer you need to post the exact error message that you see, not a vague recollection of it.
The problem might be that LocaDB is not installed, or it might be that there is some SQL Server access issue. We can't tell because you did not post the error message
I have created a C# application that connects to a SQL Server database which I created in SQL Server 2014 Management Studio. I need to send my app, my database, and instructions to get them working to someone for assessment.
My application connects perfectly on my computer with the connection string
Data Source=(local);Initial Catalog=ReportsDB;Integrated Security=True
However I am testing it on another computer and it will not connect with that same string.
I have installed SQL Server 2014 Express on that computer, and restored the database so it is identical to my main computer.
Any advice on how to make this work, or alternatively make it portable enough to submit?
The problem I had was that I assumed that connection strings were the same (apart from computer name) between SQLServer and SQLExpress however they are not.
My solution was rather hacky- I found the SQLExpress Connection String using VS on my second computer, replaced the computer name with the (local) keyword and then made an option in my application to switch between the default SQLExpress or SQLServer connection string so the user might change it manually. I also included an option to allow them to completely modify the connection string if neither default works. This is far from the most elegant solution, but with my limited understanding, it is passable to get the system working on a new computer.
I am pretty new to SQL and I'm stuck on something which is probably a few clicks away.
The program I am building will store the data in the database created on the management studio. Everything works fine on a test application. Now the question is: how should I connect to the database if I want to open the program from another computer? I tried copying the test project on a friend's computer but it cannot find the database as I suppose is obvious because the db is stored on my pc.
i know hundreds of questions like this exist around google but I'm sick of looking at forums reading complicated stuff. any help will be really appreciated.
thanks.
In the database connection settings or script you propably have database server set to 'localhost'
Try setting this to the computer network IP if the other computer is inside the same network.
To connect to it from outside the network (over the internet) You need set the database server setting to you external IP and you have to port-forward (NAT) the SQL server port to your computer.
If you can tell us what database software you are using for the Database I can tell you what port to forward, for more help with forwarding you should ask on serverfault.com and also provide your router/firwall make and model
It depends (at least partly) on how you're connecting to the database in the first place. Normally, you'll have some sort of connection string that tells what computer to connect to. It'll be set to the local computer by default, but changing it to something else is normally just a matter of editing that machine name into the string.
If you're connecting via ODBC, the program will just specify an ODBC connection, and the ODBC connection will specify the machine to connect to. You can use the "Data Sources (ODBC)" control panel to edit these (depending on the version of Windows you're using, it may be in the "Administrative Tools" folder instead of showing up directly in the control panel).
when you want to connect to a sql server over the network there are a few things you should know/check:
is your connection string correct (not localhost)
does the remote sql server accept tcp/ip connections
does the firewall of the remote compture allow the connection
Is the sqlbrowser running on the remote computer (if not you need to specify the port in your connection string.
To make sure this al works the best thing you can do is try to connect from the new pc to the remote database using sql management studio or if you don't want to install the ssms you can try to create an odbc profile that connects to the remote pc. By doing this you can determine if the problem is with the database itself or with your application.