简体   繁体   English

C#SQL Server:应用程序可与另一台PC上的数据库一起使用

[英]C# SQL Server: Application works with database from another pc

I have my application written in C#, it uses a SQL Server database. 我的应用程序用C#编写,它使用SQL Server数据库。 I have a connection to a database in my C# code, some queries to write/read from database. 我的C#代码中有一个到数据库的连接,一些查询要从数据库写入/读取。

Now consider following: if I want to run this app from another PC, this PC has no SQL Server, will this app work? 现在考虑以下问题:如果我想从另一台PC运行此应用程序,则该PC没有SQL Server,此应用程序可以工作吗? (I assume not) If not then how can this another PC still work with database? (我认为不是)如果不是,那么另一台PC仍如何与数据库一起工作? Is there a way to programmatically create database on another PC using C# so it has a name I need, columns I need. 有没有一种方法可以使用C#在另一台PC上以编程方式创建数据库,因此它具有我需要的名称和我需要的列。 I created my database using SQL Server Management Studio. 我使用SQL Server Management Studio创建了数据库。

I guess your application works with a local server. 我猜您的应用程序可以在本地服务器上使用。 First of all you should check in your application at startup if there is any local mssql server running. 首先,您应该在启动时检入应用程序,如果有任何本地mssql服务器在运行。 If not, you should handle it by installing one programmatically. 如果没有,您应该通过编程安装一个。

Read this answer how to do this if you don't know it. 阅读答案,如果不知道该怎么做。

After that you have to create the database, it's tables, maybe adding user priviliges. 之后,您必须创建数据库(即表),也许还要添加用户权限。 Write a SQL script that gets started by a class that starts it. 编写一个由启动它的类启动的SQL脚本。

Read this to see how to start a SQL script in C# 阅读本文以了解如何在C#中启动SQL脚本

You can do this by setting up SQL server on another machine (server). 您可以通过在另一台计算机(服务器)上设置SQL Server来实现。

Set that servers authentication to SQL Server authentication (requires username and password for that SQL server Management Studio) 将该服务器身份验证设置为SQL Server身份验证(需要该SQL Server Management Studio的用户名和密码)

Change the connection string in web/App.config from your C# app to use that servers Ip address and Credentails for SQL server 从C#应用程序更改web / App.config中的连接字符串,以使用该服务器的IP地址和SQL Server的Credentails

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在另一台PC上使用本地SQL Server数据库安装C#WPF应用程序 - Installing a C# WPF application with local SQL Server database on another PC 另一台PC上的C#数据库文件应用程序 - C# database file application on another pc 我用C#开发了一个应用程序,是否可以在没有SQL Server和Visual Studio的另一台PC上运行该应用程序 - I developed an application in C#, is it possible to run this application on another PC which has no SQL Server and Visual Studio 带有 sql server 的 C# wpf 应用程序只能在我的电脑上运行 - C # wpf application with sql server works only on my pc 无法在另一台 PC 上运行/访问本地 SQL Server 数据库的 C# 程序(错误 52) - C# Program which cannot run/access a local SQL Server database on another PC (Error 52) C#WPF应用程序无法在使用SQL Server CE本地数据库的另一台PC上运行 - C# WPF app does not work on another PC using SQL Server CE local database C#在多台PC上使用一个SQL Server数据库 - C# Use One SQL Server database on multiple PC 无法从Windows应用程序C#连接到SQL Server数据库 - unable to connect to sql server database from windows application c# 从SQL Server中读取数据库-C#中的WP8应用程序 - Read database from SQL Server - WP8 Application in C# 从C#应用程序安全登录到SQL Server数据库 - Secure login to a SQL Server database from C# application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM