开发者

Sharing SQL Server Between Multiple System

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.Ope开发者_如何转开发n();

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.


When you connect to the database in your code, you'll 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'd 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.


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

check here


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜