How to connect to SQL Server from a client machine? - c#

Hello everybody i have a question and confusion about a project that i developed, and I will be very happy if you help me to improve my project.
I worked in VS2010 with C# and my database is attached in Sql Server 2008. my app is supposed to work in a LAN, so i'm thinking to make two versions of this app, the first will include the database and the sql server(plus the winforms of course), the second will just contain dotNet framework and it's supposed to connect to the database installed on the other machine. Is it possible. If so, how??

yes it is posible.
alter your connection string's "data source" to "ip address of the server"
Suppose in your machine where sql server is installed you are using this connection string
"data source=localhost;initial catalog=databasename;uid=sa;pwd=password"
then in the client system you need to alter it like this
"data source=IpAddressOfTheServer;initial catalog=databasename;uid=sa;pwd=password"
Note: the application having server's ip address in connection string is accessible by both, server and the client.

if Connection String in your (c# ) code Setted, Change connection string's "Data Source" to "IP address of server"
an another way change connection string in (App Config or WebConfig) at StartUp Project by below format:
<configuration>
<connectionStrings>
<add name="DB" connectionString="Data Source=192.168.10.5;
Initial Catalog=SafetyDB;Persist Security Info=True;User ID=sa;
Password=a1234$; connection timeout=5000" />
</connectionStrings>

Related

Is There a Connection String For Connecting to Client Machine

I installed a windows form application on a client computer but when I try to log into my application it gives me this error:
a connection was successfully established with the server, but then an error occurred during the login process. (provider: shared memory provider, error: 0- No process is on the other end of the pipe.)
This is a c# windows form application running with SQL Server database, with login details. I have added the in and out bound rule on my firewall, I have tried changing my connection string severally, I have enabled tcp/ip port with its default port number, I have tried using the same network for both computers, I have tried using window and sql authentication, I have disabled firewall on client computer
Here is my connection string
<add name="connstrng" connectionString="Data Source=(local);Initial Catalog=AnyStore;Integrated Security=True"/>
I expect to be logged in to my application on the client computer using the same database with my server computer.
Connection strings are usually defined within the Web.config file. As #Panagiotis Kanavos said, the string is connecting to a local data source, which should work as expected within your dev environment. The web.config file should be located within the root directory of your project. Edit this file on the client's machine to point to the expected server / database. You may want to keep a blank or default version of this file in source control to avoid overwriting other's connection string info.
Example String:
<add name="SomeDB" connectionString="Data Source=snapdragon\SQL2k14;database=DBNAME;User Id=username; password=password" providerName="System.Data.SqlClient" />
Edit: "snapdragon" would be the host computer name. "SQL2k14" would be your sql server instance.
ok, i found the solution i changed my connection string and its working fine now, thanks guys.
here is my connection string-
<connectionStrings>
<add name="connstrng" connectionString="Data Source=DESKTOP-5I8TFY3\EMEKA;Initial Catalog=AnyStore;User ID=adminpos;Password=********" />
</connectionStrings>
</configuration>

How can connect to host's db from host?

I bought a Windows hosting from GoDaddy. I have configured the configuration settings(Adding database and publishing project's files to host)
I can access the database while running the project on the local server.
But when I transfer the project to the server, the project on the server can't do it.
I wrote my connection string to web.config file, here it is:
<add name="xyz" connectionString="Data Source=IP ADDRESS;Initial Catalog=DBNAME;User ID=USERNAME;Password=PASS;Integrated Security=False" providerName="System.Data.SqlClient" />
I used MVC and Entity Framework, I also used layered structure
Thank You.
try to check more details about the connection string that should be used with your database provider. Here you can find several examples about how to create your connection string properly in SQL SERVER.
please notice that if you are working in your host machine, you have not to specify the IP ADDRES of your SQL SERVER but the SERVER NAME just like:
Data Source=(SERVER_NAME) \ DB_INSTANCE_NAME
I hope that it's gonna be useful.

C# Remote Connectionstring SQL Server

ich got some problems connecting to the database stored on a server in the local network. I tryed almost everything, but nothing helps.
I got 2 Databases, MYSQL and MSSQL.
Configuration:
Server: 192.168.0.198
MYSQL Port: 3306
MSSQL Port: 1433
If i connect manuelly in Visual Studio it works, but if i copy the ConnectionString from the properties, it only connects to the MYSQL Database and not the MSSQL (same login, same password, same ip adress, but ports are different)
In Visual Studio is P3B-Server\P3BMSSQL for the server and db_Software for the database
Visual Studio Properties:
"Data Source=P3B-Server;Initial Catalog=db_Software;User ID=myUser;Password=mypassword"
But it doesnt work :/
I tryed
"Data Source=P3B-Server..."
#"Data Source=P3B-Server\P3BMSSQL..."
"Data Source=192.168.0.198,1433..."
"Data Source=tcp:192.168.0.198,1433..."
Still no connection to MSSQL Server, only MYSQL Server.
I`m connecting with HeidiSQL to both Databases and got
"Microsoft SQL Server (TCP/IP, experimental)" with 192.168.0.198, Port 1433,
user=myUser and Password=mypassword" for the MSSQL Server and there it works.
Checked "connectionstrings.com", but no solution works for me.
PS: Other side is an ASP.NET application, which connects with
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
(stored in Web.config) to the database.
I need exact this for my C# application as a Connectionstring.
Please help me. Thanks !
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198\P3BMSSQL;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>

C# Linq-to-sql server name when creating a release

I'm working on C# linq-to-sql application over SQL Server express 2008 . My database is inside SQL server.
I'm using Windows Authentication to connect to sql server from my application.
The server name used in connection string is related to my pc user name, so I'm wondering if I create a release of my application and put it on client pc which have SQL Server installed with another server name, would my application work?
my connection string is
<add name="WindowsFormsApplication1.Properties.Settings.OPTICA_MDFConnectionString"
connectionString="Data Source=ENG-MEDIAN-PC;Initial Catalog=OPTICA.MDF;Integrated Security=True"
providerName="System.Data.SqlClient" />
Because the app and the sql server are on the same host you can use "Data Source=.\<instance name>" which may be the default MSSQL.
That default would look like this:
connectionString="Data Source=.\MSSQL; ... "
For another example, our developer boxes' app.config uses this:
connectionString=".\DEVSQL;Initial Catalog=..."
Note that the "." is the host and that "DEVSQL" is the sql server instance name.

How to change connection string in web.config for entity framework

I need to deploy WCF. Database is SQL Server 2008 R2. Access to database is only possible from app server because of Windows Authenticaton (sql server authentication not work).
I need to change my connection string to new data source i tried but not successfull.
i have connection address and everything what i need.
My connection string :
<connectionStrings><add name="MyEntities" connectionString="metadata=res://*/MyDatabase.csdl|res://*/MyDatabase.ssdl|res://*/MyDatabase.msl;provider=System.Data.SqlClient;provider connection string="data source=myMachine-LAPTOP;initial catalog=MyDatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
to delete connection string and generate new is not possible, because i have not access from dev computer and app server dont have visual studio to try it from there.
i need help how to change it.
Please try to change connection string by opening configuration file with notepad..

Categories

Resources