将 .net 项目部署到开发服务器

发布于 2025-01-04 05:06:19 字数 560 浏览 0 评论 0原文

我在我的机器上本地开发了一个 winforms 应用程序。它从 csv 文件读取数据并从数据库查找相关信息(通过执行存储过程)。

我将其移至开发服务器并尝试运行它,但在从 app.config 文件获取 SQL 连接字符串的行处出现错误。错误是:System.NullReferenceException:未将对象引用设置为对象的实例。。当然,该应用程序在我的机器上运行良好。

我注释掉了该代码后面的所有行,并显示了错误消息。我猜这与 conn.ConnectionString 行有关。

SQL 数据库指向正确的数据库服务器& UID& pwd 是正确的。什么会导致错误?

    try
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["SilverTicker"].ConnectionString;

I developed a winforms app locally on my machine. It reads data from a csv file and looks up related information from a database (by executing a stored proc).

I moved that to the development server and tried running it, but I get an error when at the line that gets SQL connection string from app.config file. The error is: System.NullReferenceException: Object reference not set to an instance of an object.. Of course the app runs fine on my machine.

I commented out all lines following this code, and the error message is displayed. I am guessing it has to do with the conn.ConnectionString line.

The SQL database is pointing to the correct db server & UID & pwd are correct. What would be causing the error?

    try
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["SilverTicker"].ConnectionString;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏见 2025-01-11 05:06:19

代码示例中的对象之一返回“null”。我猜测它是

ConfigurationManager.ConnectionStrings["SilverTicker"].ConnectionString

在该行上放置一个断点并检查 .ConnectionStrings 集合的内容以确保它包含“SilverTicker”。

我猜测 ConfigurationManager.ConnectionStrings["SilverTicket"] 未定义(可能是因为两个环境中 app.config 之间不一致),因此访问它是 .ConnectionString 属性抛出异常。

One of the objects in your code sample is returning "null". I'm guessing that it's

ConfigurationManager.ConnectionStrings["SilverTicker"].ConnectionString

Put a breakpoint on that line and check the contents of the .ConnectionStrings collection to be sure that it contains "SilverTicker".

I'm guessing that ConfigurationManager.ConnectionStrings["SilverTicket"] is undefined (probably because of an inconsistency between app.config in the two environments), so accessing it's .ConnectionString property is throwing an exception.

再可℃爱ぅ一点好了 2025-01-11 05:06:19

检查它是否检索数据,

如果您已经编写了类似

DataSet.Table[0]

检查 tis 返回数据的内容,并且 DataSet 中必须包含表。

Check its retriving data or not

if you have written like

DataSet.Table[0]

check tis returning data and DataSet must contain table in it .

从﹋此江山别 2025-01-11 05:06:19

看起来您不需要第二个 .connectionstring。您必须将连接字符串放在 app.config 中的 connectionstrings 标记中的正确位置。该位置需要在 app.config 中指定,否则您的代码将找不到连接字符串。

Looks like you don't need the second .connectionstring. You have to put the connection string in the right place in the connectionstrings tag in the app.config. The place needs to be specific in the app.config otherwise your code won't find the connection string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文