使用脚本启用与 sql express 的远程连接
我正在使用 sql server express 2008 部署应用程序。在我的应用程序的先决条件部分中,我已包含:
因此,当用户安装我的应用程序时,它也会安装 sql express。
然后我将能够连接到该数据库引擎,如下所示:
try
{
// database should be in the same network
SqlConnection conn =
new SqlConnection(@"Data Source=.\sqlexpress; Integrated Security=True");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
现在,当我安装不同的应用程序(客户端版本)时,我希望能够连接到该数据库引擎。我设法通过执行以下操作来连接到它:
try
{
SqlConnection conn =
new SqlConnection(@"Data Source=192.168.0.120\sqlexpress,22559; USER=sa; PASSWORD=*********");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
为了使该代码正常工作,我必须执行以下操作:
所以我的问题是:
如何使用代码配置它?当我部署应用程序时,我希望我的应用程序像它一样安装 sql express,但我也想启用 tcp/IP 连接,启用一些端口,最后为帐户“SA”创建密码,因为我无法连接到如果 sa 帐户没有密码,则远程数据库。
或者也许我要求太多而我做错了事。也许我应该只为我计划部署的数据库而不是数据库引擎做这一切。任何更容易的事情。我很难部署这个,也许部署本地数据库和 wcf 服务会更容易,以便在本地数据库上远程创建 CRUD 操作。
EIDT
我发现这 3 个链接声称可以做类似的事情,但我仍然无法使其工作。
I am deploying an application with sql server express 2008. In the prerequisites section of my application I have included:
As a result when a user installs my application it will install sql express as well.
Then I will be able to connect to that database engine as:
try
{
// database should be in the same network
SqlConnection conn =
new SqlConnection(@"Data Source=.\sqlexpress; Integrated Security=True");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
Now when I install a different application(client version) I will like to be able to connect to that database engine. I managed to connect to it by doing something like:
try
{
SqlConnection conn =
new SqlConnection(@"Data Source=192.168.0.120\sqlexpress,22559; USER=sa; PASSWORD=*********");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
In order for that code to work I had to do the following:
So my question is:
How could I configure this with code? When I deploy my application I want my application to install sql express like it does but I also whant to enable tcp/IP connections, enable some ports and lastly create a password for the account "SA" because I am not able to connect to the database remotly if the sa account does not have a password.
Or maybe I am asking to much and I am doing the wrong thing. perhaps I should do all this just for the database that I am planing on deploying not the database engine. whatever is easier. I have had a hard time deploying this maybe it will be eassier to deoploy a local database along with a wcf service in order to create CRUD operations on the local database remotely.
EIDT
I found this 3 links that claim on doing something similar and I still cannot make it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下载sql server express 2008(SQLEXPR32_x86_ENU.exe)并将其放在我的C盘根目录中。然后我使用以下参数安装它:
C:\SQLEXPR32_x86_ENU.exe /q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules= RebootRequiredCheck /TCPENABLED=1
我添加 /TCPENABLED=1 以便启用 TCP/IP
downloaded sql server express 2008 (SQLEXPR32_x86_ENU.exe) and place it in the root of my c drive. then I install it with the following parameters:
C:\SQLEXPR32_x86_ENU.exe /q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /TCPENABLED=1
I add /TCPENABLED=1 in order to enable TCP/IP
我建议您创建修改后的
引导程序包
来自定义安装 Sql Server 2005 Express。作为替代方案,您还可以在安装程序中使用自定义操作来使用 SMO 更改目标服务器。
像这样的事情:
我们使用 SMO 对象创建用户登录并将用户关联到我们创建的应用程序数据库。如果数据库不可用,甚至运行 sql 脚本来创建数据库。
请参阅这些链接:
配置 SQL Express安装
配置 SQL Server(如果包含)作为要求
注意:在 App.config 文件中创建 SQL Server 连接字符串设置,而不是在代码中放入核心内容。这将帮助您自定义应用程序首先运行定制,例如数据库创建。
I suggest you to create modified
bootstrapper package
to install Sql Server 2005 Express with customzation.As an alternative, you can also use a custom action in your installer to change the targeted server using SMO.
Something like this:
We use SMO object to create user login and associate user to our created application database.. even run sql script to create database if database is not available..
Refer these links:
Configuring SQL Express During Installation
Configuring SQL Server when included as a requirement
Note: Create your sql server connection string settings in App.config file rather than putting hardcore in code.. this will help you customize application first run customization e.g. database creation.
这些可能会有一些帮助,我已经将它放在我的待办事项列表中一段时间了,对于我必须设置我的应用程序以与 Sql Server 2008 Express 一起运行的计算机。它基本上是一种设置脚本的方法,SQL08exp 安装程序将根据您在脚本中设置的内容读取并自动执行大量设置。
http://digitalformula。 net/articles/how-to-perform-an-unattended-installation-of-sql-server-2008-express/
http://blogesh.wordpress.com/2008/ 09/23/silent-install-of-sql-server-2008/
These might be of some help, I've had it on my todo list for a while for the computers I have to setup for my app to run with Sql Server 2008 Express. It's basically a way to setup a script that the SQL08exp installer will read and automate a lot of the setup according to what you set in the script.
http://digitalformula.net/articles/how-to-perform-an-unattended-installation-of-sql-server-2008-express/
http://blogesh.wordpress.com/2008/09/23/silent-install-of-sql-server-2008/