I want to develop a demo project in ASP.NET Core MVC with embedded Firebird v2.5. I read Firebird connection string information from a text file. Because I will change database in project presentation thus I must read from a text file. Or what is the your idea?
In this project I create a DbContext
file and I fill in the database information using this class:
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();
}
}
When I work locally, everything is fine. I can do all CRUD operations.
But when I upload my project, I see this screen:
An unhandled exception occurred while processing the request.
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
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()Stack Query Cookies Headers Routing
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB" Error while trying to open file FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response) FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse() FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey) FirebirdSql.Data.FirebirdClient.FbConnectionInternal.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:\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)
I added all privileges is IIS but I can't make this work - how can I solve this?