使用2010安装VS2012是否会影响C#DB工厂调用? [英] Installing VS2012 w/ 2010 affects C# DB factory calls?

查看:66
本文介绍了使用2010安装VS2012是否会影响C#DB工厂调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:

我有一个在VS 2010下使用.Net Framework 4.0开发的项目.

I have a project developed under VS 2010 with .Net framework 4.0.

在安装VS 2012之前,对于ODBC连接,以下代码可以完美运行(绝不会出现任何问题):

Before installing VS 2012, the following code ran perfectly (never any issue) for ODBC connections:

public void OpenDBConnectionToSource(TaskClass.SourceObject so)
        {
            try
            {
                connectionSource = factory.CreateConnection();
                connectionSource.ConnectionString = so.ConnectionString;
                connectionSource.Open();
            }
            catch (OdbcException ex)
            {
                throw;  
            }
            catch (SqlException ex)
            {
                throw;  
            }
            catch (Exception ex)
            {
                throw; 
            }
        }

现在,在安装VS 2012之后:

Now, after installing VS 2012:

1)我不能再以调试模式"运行与"any cpu"一起使用.它返回与体系结构相关的错误(猜测32与64位ODBC驱动程序问题)

1) I can no longer run in "debug mode" with "any cpu". It returns an architecture related error (guessing the 32 vs 64 bit ODBC driver issue)

2)我更改为在"x86"中调试而且代码现在只运行一半时间. Open()方法的另一半抛出以下异常:

2) I change to debug in "x86" and the code only runs half the time now. The other half the Open() method throws the following exception:

{"ERROR [IM004] [Microsoft] [ODBC驱动程序管理器] SQL_HANDLE_ENV上驱动程序的SQLAllocHandle失败" }

3)如果我卸载VS2012,则一切运行正常.

4)如果我将上述源代码更改为特定于ODBC(例如,使用类似

4) If I change the above source code to be ODBC specific (eg, using calls like

OdbcConnection connectionSource =新的OdbcConnection(SettingsManager.SourceConnection)

OdbcConnection connectionSource = new OdbcConnection(SettingsManager.SourceConnection)

),而不是更通用的工厂调用,效果很好.不幸的是,我无法将其永久更改为ODBC专用,因为与SQLServer相关的方法也可能会使用它.

当前的项目尚不能移植到VS 2012,但我们必须开发一些新的东西VS 2012,所以我也不能完全卸载它.

其他人有没有遇到过类似的经历?或有任何可能的建议尝试?

Has anyone else experienced anything like this? Or would have any possible suggestions to try?

谢谢!

推荐答案

我不知道有任何问题,但是.NET 4.5会覆盖.NET 4.0,因此与是否使用它无关,您是否在v4应用程序上运行.NET 4.5二进制文件. ;如果有错误,它将在运行时库中.

I'm not aware of any issues but .NET 4.5 overwrites .NET 4.0 so irrelevant of whether you're using it or not you are running the .NET 4.5 binaries on a v4 app.  If there is a bug it would be in the runtime library. 

通常,不建议您将应用作为任何CPU"运行.这不再是默认设置,因为它可能会引起问题.如果您在x64操作系统上运行,则说明您的应用正在使用64位ODCB驱动程序.听起来你想坚持 x86驱动程序,因此您需要配置您的应用程序以使用该平台.

In general it is not recommended that you run apps as Any CPU.  That is no longer the default because it can cause problems.  If you're running on a x64 OS then you're app is using the 64-bit ODCB drivers.  It sounds like you want to stick with the x86 drivers so you'll need to configure your app to use that platform.

您不确定正在使用的工厂.通常,除非您以不支持的数据库为目标,否则您不会使用ODBC.如果您使用的是ODBC,那么连接字符串是否是DSN名称?如果是,您是否为平台配置了它 您要定位? x64和x86使用不同的DSN条目.如果您要针对多个数据库,则通常会坚持使用ADO.NET中较为通用的提供程序,该提供程序将基于连接字符串(SqlConnection创建正确的提供程序 SQL,OracleConnection for Oracle等).

You didn't identify what factory you're using.  In general you wouldn't use ODBC unless you are targeting an unsupported database.  If you are using ODBC then is the connection string a DSN name?  If so did you configure it for the platform you're targeting?  x64 and x86 use different DSN entries.  If you are targeting multiple DBs then you'll generally stick with the more generic provider from ADO.NET that will create the correct provider based upon the connection string (SqlConnection for SQL, OracleConnection for Oracle, etc).

我建议您将问题缩小到最少的代码,然后在Connect( http://connect.microsoft .com ).他们可以确认是否是错误.

I would recommend that you narrow down the problem to the minimal amount of code and then report it to MS at Connect (http://connect.microsoft.com). They can confirm whether it is a bug or not. 

Michael Taylor-2013年1月2日
http://msmvps.com/blogs/p3net

Michael Taylor - 1/22/2013
http://msmvps.com/blogs/p3net


这篇关于使用2010安装VS2012是否会影响C#DB工厂调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆