Visual Studio 2012使用外部DataBase发布项目c#

时间:2022-01-31 09:51:46

I need your help guys on how to publish correctly a project that I have created on Visual Studio.

我需要你的帮助人员如何正确发布我在Visual Studio上创建的项目。

Here is the thing my project runs successfully on my local computer (and also the publish file) but when I try to run it (for test purposes to a different computer I receive error messages due to sql connection). My application is connected to Sql Database with a connection string (Data Source= HP-PC\SQLEXPRESS;Initial Catalog=Stock;Integrated Security=True).

这是我的项目在我的本地计算机(以及发布文件)上成功运行的事情,但是当我尝试运行它时(为了测试目的,我收到由于sql连接而导致的错误消息)。我的应用程序通过连接字符串连接到Sql Database(数据源= HP-PC \ SQLEXPRESS;初始目录=库存;集成安全性= True)。

I handle the database with Sql Manager, and here is some of the errors that I receive when I try to run my application to another computer:

我使用Sql Manager处理数据库,这是我尝试将应用程序运行到另一台计算机时收到的一些错误:

System.Data.SqlClient.SqlException (0x80131904): Παρουσιάστηκε ένα σφάλμα δικτύου ή ένα σφάλμα που αφορά μια συγκεκριμένη παρουσία κατά τη δημιουργία μιας σύνδεσης σε SQL Server. Δεν ήταν δυνατή η εύρεση του διακομιστή ή ο διακομιστής δεν ήταν προσβάσιμος. Βεβαιωθείτε ότι το όνομα παρουσίας είναι σωστό και ότι ο SQL Server έχει ρυθμιστεί ώστε να επιτρέπει τις απομακρυσμένες συνδέσεις. (provider: SQL Network Interfaces, error: 26 - Προσδιορίστηκε σφάλμα εντοπισμού διακομιστή/περιόδου λειτουργίας)
   σε System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   σε System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   σε System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   σε System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   σε System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   σε System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   σε System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   σε System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   σε System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   σε System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   σε System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   σε System.Data.SqlClient.SqlConnection.Open()
   σε System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
Error Number:-1,State:0,Class:2

propably as I understand my publish option was not contain at all the db.

据我所知,我的发布选项根本不包含db。

How can I publish my project correctly with the external database? or is better to include my db inside the project?

如何使用外部数据库正确发布项目?或者最好将我的数据库包含在项目中?

2 个解决方案

#1


0  

The English error (using Google translate) is:

英语错误(使用谷歌翻译)是:

There was a network error or a specific instance error when you created a connection to SQL Server. The server could not be found or the server was not accessible. Make sure the instance name is correct and that SQL Server is configured to allow remote connections. (Provider: SQL Network Interfaces, error: 26 - Server / session detection error)

创建与SQL Server的连接时出现网络错误或特定实例错误。找不到服务器或服务器无法访问。确保实例名称正确并且SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 服务器/会话检测错误)

This means that your application is not able to connect to your SQL Server. The first thing to check would be:

这意味着您的应用程序无法连接到您的SQL Server。首先要检查的是:

Are you able to connect to the SQL Server manually from the machine in which you have deployed your application ?

您是否可以从部署应用程序的计算机上手动连接到SQL Server?

It is likely that the SQL Server is not configured to accept connections from remote machines.

SQL Server可能未配置为接受来自远程计算机的连接。

There is a good article on step-by-step ways to troubleshoot the connection issue:

有一篇很好的文章介绍了解决连接问题的分步方法:

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine

#2


0  

Hi guys after a lot of search and testing I found the best solution to my issue and I want to share with you. Well the problem was the server name and nothing else since (I don't any user name or password) so in my code I just change a single value on connection string from

嗨,大家经过大量的搜索和测试,我找到了解决问题的最佳解决方案,我想与大家分享。那么问题是服务器名称,因为(我没有任何用户名或密码)所以在我的代码中我只是更改连接字符串上的单个值

"Data Source= HP-PC\\SQLEXPRESS;Initial Catalog=Stock;Integrated Security=True"

To

string hostName = System.Net.Dns.GetHostName();

"Data Source= '"+hostname+'"\\SQLEXPRESS;Initial Catalog=Stock;Integrated Security=True"

and everything is fine now I can test my app to any computer!!!!

一切都很好,现在我可以测试我的应用程序到任何计算机!

Thank you guys for your time and help,

谢谢你们的时间和帮助,

Friendly regards, Jim

友好的问候,吉姆

#1


0  

The English error (using Google translate) is:

英语错误(使用谷歌翻译)是:

There was a network error or a specific instance error when you created a connection to SQL Server. The server could not be found or the server was not accessible. Make sure the instance name is correct and that SQL Server is configured to allow remote connections. (Provider: SQL Network Interfaces, error: 26 - Server / session detection error)

创建与SQL Server的连接时出现网络错误或特定实例错误。找不到服务器或服务器无法访问。确保实例名称正确并且SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 服务器/会话检测错误)

This means that your application is not able to connect to your SQL Server. The first thing to check would be:

这意味着您的应用程序无法连接到您的SQL Server。首先要检查的是:

Are you able to connect to the SQL Server manually from the machine in which you have deployed your application ?

您是否可以从部署应用程序的计算机上手动连接到SQL Server?

It is likely that the SQL Server is not configured to accept connections from remote machines.

SQL Server可能未配置为接受来自远程计算机的连接。

There is a good article on step-by-step ways to troubleshoot the connection issue:

有一篇很好的文章介绍了解决连接问题的分步方法:

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine

#2


0  

Hi guys after a lot of search and testing I found the best solution to my issue and I want to share with you. Well the problem was the server name and nothing else since (I don't any user name or password) so in my code I just change a single value on connection string from

嗨,大家经过大量的搜索和测试,我找到了解决问题的最佳解决方案,我想与大家分享。那么问题是服务器名称,因为(我没有任何用户名或密码)所以在我的代码中我只是更改连接字符串上的单个值

"Data Source= HP-PC\\SQLEXPRESS;Initial Catalog=Stock;Integrated Security=True"

To

string hostName = System.Net.Dns.GetHostName();

"Data Source= '"+hostname+'"\\SQLEXPRESS;Initial Catalog=Stock;Integrated Security=True"

and everything is fine now I can test my app to any computer!!!!

一切都很好,现在我可以测试我的应用程序到任何计算机!

Thank you guys for your time and help,

谢谢你们的时间和帮助,

Friendly regards, Jim

友好的问候,吉姆