我想在 ASP.NET Core 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”的“CreateFile(打开)”操作期间出现 I/O 错误
尝试打开文件时出错
FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse 响应)
FbException:文件“C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB”的“CreateFile(打开)”操作期间出现 I/O 错误
尝试打开文件
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()时出错堆栈查询 Cookie 标头路由
IscException:文件“C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB”的“CreateFile(打开)”操作期间的 I/O 错误尝试打开文件 FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException( IResponse 响应)FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse() FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey) FirebirdSql.Data.FirebirdClient.FbConnectionInternal 。连接()
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:\Users\MD\source\repos\GDIWebApplication\Models\Context\DbContext.cs:line 60
at GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in C:\Users\MD\source\repos\GDIWebApplication\Models\Repositories\ProductRepository.cs:line 20
at GDIWebApplication.Controllers.ProductController.Index(String search) in C:\Users\MD\source\repos\GDIWebApplication\Controllers\ProductController.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,但我无法完成这项工作 - 我该如何解决这个问题?