Έχω φάει αρκετή ώρα προσπαθώντας να καταφέρω να γίνεται Attach μια βάση δεδομένων από C# κώδικα.
Κάτι το οποίο με τον ίδιο τρόπο έχω ξανακάνει σε άλλο Web Project μάλιστα.
Server mServer = new Server(Parameters.Config.ServerAddress);
mServer.AttachDatabase(Parameters.Config.DbName, new StringCollection {
Parameters.Config.DatabaseMdfFile,
Parameters.Config.DatabaseLdfFile }, AttachOptions.None);
Βλέπεται κάτι το περίεργο?
Το Exception είναι:
Failed to connect to server .
Inner:
{"A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or was
not accessible. Verify that the instance name is correct and that SQL
Server is configured to allow remote connections. (provider: Named Pipes
Provider, error: 40 - Could not open a connection to SQL Server)"}
Parameters.Config.ServerAddress <= .
Parameters.Config.DatabaseMdfFile <= Full DirectoryPath + File Name
Parameters.Config.DatabaseLdfFile <= Full DirectoryPath + File Name
Είναι Checked while debugged code.
O SQL Server έχει enabled TCP/IP, Named Pipes όπως π.χ. λέει και το Exception.
Όταν την κάνω attach μέσα από το Visual Studio όλα λειτουργούν κανονικά!
Έχω δοκιμάσει με το όνομα του Server...τίποτα. Δοκίμασα με καρφώτα plain string path filenames...μπα...
Όσον αφορά τα rights δεν μπορώ να καταλάβω γιατί να μην έχω δικαιώματα, admin του υπολογιστή είμαι.
Καμμιά ιδέα??