在数据库中使用ODBC驱动程序查询结果,但在C#中不填充数据库,没有错误

发布于 2025-02-10 14:09:13 字数 1544 浏览 2 评论 0原文

刚刚开始使用Windows 11并为32位和64位安装了Oracle驱动程序,使用C#从Oracle数据库中获取数据。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient; 
 
namespace ApexAutoEmailConsol
{
    static class ServiceLog
    {
        static String connectionString = "Dsn=Prod21_32;uid=ebseb;pwd=ebseb";
        static string strQuery = string.Empty;
         
        public static string OutstandingInvoices()
        {
            try
            {
                OdbcConnection oCon = new OdbcConnection();
                oCon.ConnectionString = connectionString;
                oCon.Open();

                DataTable dtSales = new DataTable();

                strQuery = "SELECT * from apps.org_organization_definitions HO";
               // if I run above query in Toad it's giving result.
                OdbcDataAdapter myAdp = new OdbcDataAdapter(strQuery, oCon);
                myAdp.Fill(dtSales);
                
                //Adapter not filling data to the datatable.
                if (dtSales.Rows.Count <= 0)
                {
                    return "";
                }
 
                return strReturn;
            }
            catch (Exception Ex)
            {
                WriteErrorLog(Ex.ToString());
                return "";
            }
        }    
}

当我复制Strquery并在蟾蜍上运行时,获取结果,但数据仍然为空。

问题是什么?同一代码在我的Windows10计算机上正常工作。

Just started using windows 11 and installed Oracle drivers for 32Bit and 64Bit, wrote program using C# to fetch data from Oracle database.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient; 
 
namespace ApexAutoEmailConsol
{
    static class ServiceLog
    {
        static String connectionString = "Dsn=Prod21_32;uid=ebseb;pwd=ebseb";
        static string strQuery = string.Empty;
         
        public static string OutstandingInvoices()
        {
            try
            {
                OdbcConnection oCon = new OdbcConnection();
                oCon.ConnectionString = connectionString;
                oCon.Open();

                DataTable dtSales = new DataTable();

                strQuery = "SELECT * from apps.org_organization_definitions HO";
               // if I run above query in Toad it's giving result.
                OdbcDataAdapter myAdp = new OdbcDataAdapter(strQuery, oCon);
                myAdp.Fill(dtSales);
                
                //Adapter not filling data to the datatable.
                if (dtSales.Rows.Count <= 0)
                {
                    return "";
                }
 
                return strReturn;
            }
            catch (Exception Ex)
            {
                WriteErrorLog(Ex.ToString());
                return "";
            }
        }    
}

When I copy strQuery and run on Toad, getting result but datatable is still empty.

What is the problem? The same code is working perfect on my Windows10 machine.

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

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

发布评论

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

评论(2

甜点 2025-02-17 14:09:14

un 提交 TED数据仅在创建它的会话中可见(并且,如果没有CONDE> CONDE> CONDE> CONDE> CODER在会话结束时将可见。泰德)。如果您看不到另一个会话(C#)的数据,请确保已在SQL客户端(TOAD)中发布了commit命令。

如果您已经发布了commit,但仍然看不到数据,请确保SQL客户端(TOAD)和C#程序都连接到同一数据库,并在查询同一用户的架构该数据库。

UnCOMMITted data is only visible within the session that created it (and will ROLLBACK at the end of the session if it has not been COMMITted). If you can't see the data from another session (C#) then make sure you have issued a COMMIT command in the SQL client (Toad).

If you have issued a COMMIT and still can't see the data then make sure that both the SQL Client (Toad) and the C# program are connecting to the same database and are querying the same user's schema of that database.

生寂 2025-02-17 14:09:14

这是非常独特的问题,大约在2年前,我用另一台机器遇到了它,在那里我无法在蟾蜍中获得一些查询结果。一些查询正在工作,但是一些具有特定表格的查询是空的结果。那个时候,我在环境变量中添加了以下语言设置并进行了工作。
nls_lang = American_america.utf8

在我的新机器中使用了相同的使用,现在可以通过Visual Studio 2022获得结果。

It's very unique problem, I had it around 2 years ago with my another machine, where I was not able to get some query result in Toad. Some queries are working but some of with specific table in joing was giving empty result. That time I added following language setting in my environment variable and was worked.
NLS_LANG = American_America.UTF8

Used same in my new machine and now am getting result with Visual Studio 2022.

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