火鸟阅读iis asp.net核心5上的数据库问题



我想用ASP开发一个演示项目。NET核心MVC与嵌入式Firebird v2.5。我从一个文本文件中读取了Firebird连接字符串信息。因为我将在项目演示中更改数据库,所以我必须从文本文件中读取。或者你们的想法是什么?

在这个项目中,我创建了一个DbContext文件,并使用以下类填充数据库信息:

public class DbContext
{
string startupdirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)+"\settings.txt";
string dblocation = string.Empty;
string userName = string.Empty;
string pass = string.Empty;
int port = 0;
string dataSource = string.Empty;

public DbContext()
{
if (File.Exists(startupdirectory))
{
string[] allData = File.ReadAllLines(startupdirectory);
dblocation = allData[0].ToString();
userName = allData[1].ToString();
pass = allData[2].ToString();
port = Convert.ToInt32(allData[3].ToString());
dataSource = allData[4].ToString();
}
}
public string GetConnectionString()
{
FbConnectionStringBuilder csb = new();
csb.Database = dblocation;
csb.DataSource = dataSource;
csb.UserID = userName;
csb.Password = pass;
csb.ServerType = FbServerType.Default;
csb.Port = port;
//i added below code for embedded db
csb.Dialect = 3;
csb.Role = "";
csb.ConnectionLifeTime = 15;
csb.Pooling = true;
csb.MinPoolSize = 0;
csb.MaxPoolSize = 50;
csb.PacketSize = 8192;
return csb.ToString();
}
public FbConnection GetConnection()
{
string connectionString = GetConnectionString();
FbConnection connection = new();
connection.ConnectionString = connectionString;
connection.Open();
return connection;
}
public void KillConnection(FbConnection connection)
{
connection.Close();
connection.Dispose();
}
}

当我在当地工作时,一切都很好。我可以执行所有CRUD操作。

但当我上传我的项目时,我会看到这个屏幕:

处理请求时发生未处理的异常。

IscException:在";创建文件(打开(";文件操作";C: \Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB">

尝试打开文件时出错

火鸟Sql。数据客户管理。GdsConnection。HandleResponseException(IResponse响应(

FbException:在";创建文件(打开(";文件操作";C: \Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB">

尝试打开文件
FirebirdSql时出错。数据火鸟客户端。FbConnection内部。Connect((

堆栈查询Cookie标头路由

IscException:在";创建文件(打开(";文件操作";C: \Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"尝试打开文件时出错火鸟Sql。数据客户管理。GdsConnection。HandleResponseException(IResponse响应(火鸟Sql。数据客户管理。版本10.GdsDatabase.ReadResponse((火鸟Sql。数据客户管理。Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb,字符串数据库,byte[]cryptKey(火鸟Sql。数据火鸟客户端。FbConnection内部。Connect((

Show raw exception details
FbException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB" Error while trying to open file
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
FirebirdSql.Data.FirebirdClient.FbConnection.Open()
GDIWebApplication.Controllers.DbContext.GetConnection() in DbContext.cs
GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in ProductRepository.cs
GDIWebApplication.Controllers.ProductController.Index(string search) in ProductController.cs
lambda_method1(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Show raw exception details
FirebirdSql.Data.FirebirdClient.FbException (0x80004005): I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
---> FirebirdSql.Data.Common.IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
at FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, String database, Byte[] cryptKey)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at GDIWebApplication.Controllers.DbContext.GetConnection() in C:UsersMDsourcereposGDIWebApplicationModelsContextDbContext.cs:line 60
at GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in C:UsersMDsourcereposGDIWebApplicationModelsRepositoriesProductRepository.cs:line 20
at GDIWebApplication.Controllers.ProductController.Index(String search) in C:UsersMDsourcereposGDIWebApplicationControllersProductController.cs:line 16
at lambda_method1(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

我添加的所有权限都是IIS,但我无法使其工作-我该如何解决此问题?

您没有使用Firebird Embedded。当您指定FbServerType.Default(这也是默认值(时,您正在使用TCP/IP通过普通的Firebird服务器进行连接,错误表明数据库文件不存在(或者Firebird server进程可能没有足够的访问权限来打开文件(。

如果您真的想使用Firebird Embedded(我个人认为这对于服务器应用程序来说不是一个好主意(,则需要指定FbServerType.Embedded。还要确保数据库文件实际存在于dataSource指定的服务器上的C:FirmaBlinePalmeWEBMandanten11PalmeITGDI21.FDB

最新更新