Windows Server 2008上的SQL连接字符串

时间:2021-06-15 15:55:48

I need to connect my C# desktop app on PC 1 with database that exist on SQL server instance at Windows Server 2008. First I cannot make my connection string works.

我需要将PC 1上的C#桌面应用程序与Windows Server 2008上SQL Server实例上存在的数据库连接起来。首先,我无法使连接字符串正常工作。

My connection string is:

我的连接字符串是:

Server=(Server_Ip)192.168.1.115\(InstanceName)SQLExpress8;initial
catalog=My_Database;integrated security=True;MultipleActiveResultSets=True;

I also tried:

我也尝试过:

Server=(ServerName)DATABASE\(InstanceName)SQLExpress8;initial
catalog=My_Database;integrated security=True;MultipleActiveResultSets=True;

But that doesn't work.

但这不起作用。

By the way I have replaced server with datasource and it still doesn't work.

顺便说一句,我用数据源替换了服务器,它仍然无法正常工作。

1 个解决方案

#1


1  

I am not sure if you are putting the parenthesis in your connection string but this is an example of a working one for sql server

我不确定您是否将括号放在连接字符串中,但这是一个用于sql server的工作示例

connectionString="Server=testServer\instanceName; uid=readOnlyUser; pwd=1234567; database=testDatabase" providerName="System.Data.SqlClient"

where

testServer = IP or server name
instanceName = instance name, sometimes SQLExpress for sql server express
testDatabase = database name
uid = user name
pwd = password

you CAN connect your windows app to the database, however the server IP has to be public to the internet, you will have to mess with firewall settings in order to do that to allow the IP to be accessed publicly.

你可以将你的Windows应用程序连接到数据库,但是服务器IP必须公开到互联网,你必须搞乱防火墙设置,以便允许公开访问IP。

#1


1  

I am not sure if you are putting the parenthesis in your connection string but this is an example of a working one for sql server

我不确定您是否将括号放在连接字符串中,但这是一个用于sql server的工作示例

connectionString="Server=testServer\instanceName; uid=readOnlyUser; pwd=1234567; database=testDatabase" providerName="System.Data.SqlClient"

where

testServer = IP or server name
instanceName = instance name, sometimes SQLExpress for sql server express
testDatabase = database name
uid = user name
pwd = password

you CAN connect your windows app to the database, however the server IP has to be public to the internet, you will have to mess with firewall settings in order to do that to allow the IP to be accessed publicly.

你可以将你的Windows应用程序连接到数据库,但是服务器IP必须公开到互联网,你必须搞乱防火墙设置,以便允许公开访问IP。