microsoft / microsoft/sqlmanagementobjects
[Feature] Copy objects from live Server to offline (design mode) Server
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 143
- Fork
- 28
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
It would be really great if there were a way to transfer object definitions from a live server to an offline server.
My use case is that I am designing an application which allows users to compile many database objects from different instances into a single hierarchy, then generate a script to create that hierarchy on an arbitrary instance of SQL Server.
To accomplish this, I was hoping to add the online objects selected by the user to an offline (design mode) Server, then use SMO's scripting capabilities to script the entire tree to a .sql file.
For example:
var onlineServerConnection = new ServerConnection(new SqlConnection(/* ... */));
var onlineServer = new Server(onlineServerConnection);
var onlineDatabase = onlineServer.Databases["SmoTestDatabaseOnline"];
var onlineTable = onlineDatabase.Tables["SmoTestTable"];
var offlineServerConnection = new ServerConnection { ServerVersion = new ServerVersion(15, 0), TrueName = "designMode" };
var offlineServer = new Server(offlineServerConnection);
(offlineServer as ISfcHasConnection).ConnectionContext.Mode = SfcConnectionContextMode.Offline;
var offlineDatabase = new Database
{
Parent = offlineServer,
Name = "SmoTestDatabaseOffline"
};
onlineTable.Parent = offlineDatabase;
offlineDatabase.Tables.Add(onlineTable);
offlineServer.Databases.Add(offlineDatabase);
But I'm met with Microsoft.SqlServer.Management.Smo.FailedOperationException: SetParent failed for Table 'dbo.SmoTestTable'. ---> Microsoft.SqlServer.Management.Smo.InvalidSmoOperationException: Cannot perform the operation on this object, because the object is a member of a collection..
If I remove the onlineTable.Parent = offlineDatabase;, I am instead met with Microsoft.SqlServer.Management.Smo.FailedOperationException: Parent property of object [dbo].[SmoTestTable] does not match the collection's parent to which it is added.
I also attempted to use the Transfer class to accomplish this, but was met with Microsoft.SqlServer.Management.Common.TransferException: An error occurred while transferring data. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): 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)
var onlineDatabase = onlineServer.Databases["SmoTestDatabaseOnline"];
var onlineTable = onlineDatabase.Tables["SmoTestTable"];
//--------------------------------------------------
var transfer = new Transfer(onlineDatabase)
{
DestinationServer = offlineServer.Name,
DestinationDatabase = offlineDatabase.Name,
CopyAllObjects = false,
CopySchema = true
};
transfer.ObjectList.Add(onlineTable);
transfer.TransferData();
offlineServer.Refresh();
offlineDatabase.Refresh();
As it stands, the only conceivable way to accomplish what I want to do would be to create a new Table object and individually copy all properties onlineTable to it. But this is cumbersome and prone to error.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với các điểm vào Server, Database, Table và Transfer được hiển thị trong issue, tập trung vào việc parenting trong chế độ thiết kế offline và hành vi transfer. Xác định một cách được hỗ trợ để sao chép các định nghĩa đối tượng từ một server đang hoạt động sang một server offline và tạo script cho hệ phân cấp kết quả mà không kết nối đến một instance đích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp
- Lĩnh vực
- database
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 30/100