Oprette forbindelse til Access eller SQL server
Hej EksperterJeg er igang med at udforske ASP.NET 2.0, og har i den forbindelse lavet en application.
Det har egentligt gået meget nemt, men jeg er løbet på et lille problem nu, hvor jeg gerne vil lave en databaseforbindelse.
Jeg har installeret en SQL-Server som kører localt på min computer, som jeg har prøvet at komme i kontakt med, men får følgende fejlbesked når jeg prøver at kalde 'Open' metoden på connection attributten.
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Koden ser sådanne ud:
odbcConnection = new OdbcConnection(WebConfigurationManager.ConnectionStrings["standard"].ConnectionString);
odbcConnection.Open(); <--- fejler her
dbCommand = new OdbcCommand();
dbCommand.Connection = odbcConnection;
dbCommand.CommandType = CommandType.Text;
Og connectionstring ser sådanne ud, i min web config fil.
"Driver={SQL Server};Server=localhost;Database=jehe;Trusted_Connection=yes;
Derudover har jeg prøvet at lave en Access fil, og forbinde til den.
Med nedenstående connectionstring fik jeg samme fejlmeddelse.
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\jehe\App_Data\db.mdb;"
Dog prøvede jeg så med denne,
"Driver={Microsoft Access Driver(*.mdb)};Dbq=C:\Inetpub\wwwroot\jehe\App_Data\db.mdb;"
og fik faktisk hul igennem. Dog melder browseren tilbage, efter at den har åbnet forbindelsen og hentet data ud, med følgende mærkelige fejlmeddelse.
-----------------------------------------------------------------
Server Error in '/jehe' Application.
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
-----------------------------------------------------------------
Jeg har selvfølgelig tjekket at IIS har read/write addgang til App_Data og at filen findes på den angivne position.
Håber der er nogle derude der har lidt ekspertise inden for dette område.