gpt4 book ai didi

c# - OdbcConnection open() 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:46 25 4
gpt4 key购买 nike

protected OdbcConnection conectarBD()
{
String StringDeConexion = "Data Source=PABLOZN\\SQLEXPRESS;Initial Catalog=Proyecto2;Integrated Security=True";

try
{
OdbcConnection conexion = new OdbcConnection(StringDeConexion);
conexion.Open();
return conexion;
}
catch (Exception ex)
{
Label3.Text = ex.StackTrace.ToString();
return null;
}
}

问题是,当我浏览我的网站时,Label 在第 18 行显示此异常:

en System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) en System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) en System.Data.Odbc.OdbcConnectionOpen..ctor(OdbcConnection outerConnection, OdbcConnectionString connectionOptions) en System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) en System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) en System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions
userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&
connection) en
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection
outerConnection, DbConnectionFactory connectionFactory,
TaskCompletionSource
1 retry, DbConnectionOptions userOptions) en System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) en System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) en System.Data.Odbc.OdbcConnection.Open() en index.conectarBD() en c:..\Documents\Visual Studio 2012\WebSites\Proyecto\index.aspx.cs:línea 18

最佳答案

验证用户是否有权访问数据库。你如何使用可信连接,验证当前用户是否有权访问数据库。如果您的应用程序是 web ,请确保 NETWORKSERVICE 可以连接到数据库。

您也可以尝试在 Windows ODBC 管理器中通过 DSN 配置连接字符串。

关于c# - OdbcConnection open() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29178984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com