0

I have three computer in a office and I have installed my C#-2005 Project on all three

computers. But Problem is that Boss wants Sql-server-2000 on One PC out of three and other

would share the same.

I don’t know how to share Sql-server-2000 between three PC?. How to do?.

Confusion:-

Thanks for your co-operation but here I have a confusion on majority people said to check

TCP/IP address and consider the Connection string as per main server from client PC.

Suppose I have financial project and there would be thousand of connection string in a

project. As per above I have to change thousand of connection string as per main pc.

Now think it is a one customer's need If I have ten cutomer having same offer than think How much time I have to waste on it?. I have to modify thousand of connection string ten time more?.

If it is true than it will take lots of time on installation to each customer.

I don’t know if it is only way?.

The Connection string I have utilized on my each winform is as below:

string connstr = "server=.;initial catalog=maa;uid=mah;pwd=mah";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();

Here suggested about Config File and same I don't know if some body give me idea about how to consider it with my C#2005 project than it will save my lots time.

11
  • if the three machines are connected via LAN then just use the IP address of the machine where SQLserver is installed to connect to it from the other two. Commented Sep 22, 2011 at 17:22
  • You don't need to "share" SQL Server...you just need to have the client tools installed on the other two and the application can connect to the database on the third machine. Commented Sep 22, 2011 at 17:23
  • @StingyJack Sharing means Only one computer stored sql server and other shared it like read and write data. Commented Sep 22, 2011 at 17:24
  • @Mahesh, then thats the way SQL was designed to work. One instance, many callers. Commented Sep 22, 2011 at 17:30
  • 1
    "there would be thousand of connection string in a project." - there shouldn't be. The connection string should appear once, in a config file, and everything that wants a connection should then read it from config. Without knowing what data access tech you're using, I can't give a concrete example. Commented Sep 23, 2011 at 6:40

4 Answers 4

3

When you connect to the database in your code, you'll need a database connection string of some sort somewhere in there. Figure out the connection string for the Database server and set your code to point to that database server's connection info; I bet you currently you have it pointed at localhost

If you're using SQL Server you may need to enable remote connections on the database server.

added: you may need to modify firewall settings as well to allow SQL Server traffic (thanks Jared)

.

Edit: For putting the configuration string into a central location.

Your posted code

string connstr = "server=.;initial catalog=maa;uid=mah;pwd=mah";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();

Change to

Assuming your application has a App.Config file then you'd add an entry in there like

<add key="DBConnectionString" value="server=.;initial catalog=maa;uid=mah;pwd=mah"/>

And change your C# code to be like

string connstr = ConfigurationManager.AppSettings["DBConnectionString"];
SqlConnection conn = new SqlConnection(connstr);
conn.Open();

Putting the ConfigManager call into a class might be a good idea if you have a lot of settings to retrieve and/or believe the configuration storage methodology might change down the road. Going with the above example is WAY better than having the string literal scattered throughout your code.

Sign up to request clarification or add additional context in comments.

3 Comments

As Damien said in his comment on your question, the connection string value should be stored once and once only, such as in a configuration file. If you have the connection string text scattered throughout your code, then you're going to have the exact problem it sounds like you're having. Changing your code to point to a centrally stored connection string value is going to be the way to go; this shouldn't be too difficult a change.
I have utilized using System.Configuration in application but There are ConfigurationManager class is not found in such assembly. what am I missing?.
it solve the problem that I have add System.configuration dll to assembly and it works but here still the problem is as it is. the above throw error like: "The ConnectionString Property has not been Initialize"
2

Enable theTCP/IP connection in SQL Server. So that you can connect remotely from any pc within the network

check here

Comments

1

If your problem is that you embedded your connection string in the code, then you are going to have to do some refactoring. These would be the general steps, you will have to tailor them a bit to your situation.

  1. Add your connection string to the app.config file.
  2. Create a static/shared method that will read the connection string from the config file.
  3. Do a find and replace in your solution to replace all of the hard coded connection strings in your code with the (class and) name of the method that gets the connection string.

This is probably going to be easier than rewriting all of your data calls to use something like enterprise library or EF.

Comments

0

You will need to do as the others suggested, such as changing the connection string and enabling TCP/IP within SQL Server, but you will also likely need to configure your firewall to allow requests to SQL Server (default port of 1433) through.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.