2012-02-19 3 views
0

인덱스 복제를 실행하려고하는데 SQL DB에 데이터를 복제 할 수없는 것 같습니다. 문서 및 다른 Stackoverflow 항목을 보았다 here,하지만 뭔가를 놓치고 있어야합니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니까? 나는 내가 가까웠다 고 생각한다.RavenDB - 인덱스 복제

색인 "Questions/VoteTotals"는 내 Raven 인스턴스에 존재합니다.

코드 :

class Program 
{ 
    static void Main(string[] args) 
    { 
     CreateRdbmsSchema(); 

     using (var documentStore = new DocumentStore { Url = "http://localhost:8080" }.Initialize()) 
     { 
      documentStore.DatabaseCommands.PutIndex("Questions/VoteTotals", 
                new IndexDefinitionBuilder<Question> 
                { 
                 Map = questions => from question in questions 
                      select new 
                      { 
                       question.Title, 
                       VoteCount = question.Votes.Count 
                      } 
                }, 
                overwrite: true); 

      using(var s = documentStore.OpenSession()) 
      { 
       var q = new Question 
       { 
        Id = "questions/6", 
        Title = "How to replicate to SQL Server!?", 
        Votes = new List<Vote> 
        { 
         new Vote {Up = true, Comment = "Good!"}, 
         new Vote {Up = false, Comment = "Nah!"}, 
         new Vote {Up = true, Comment = "Nice..."}, 
         new Vote {Up = false, Comment = "No!"}, 
        } 
       }; 



      var replicationDocument = new Raven.Bundles.IndexReplication.Data.IndexReplicationDestination 
       { 
        Id = "Questions/VoteTotal", 
        ColumnsMapping = 
         { 
          {"Title", "Title"}, 
          {"UpVotes", "UpVotes"}, 
          {"DownVotes", "DownVotes"}, 
         }, 
        ConnectionStringName = "Reports", 
        PrimaryKeyColumnName = "Id", 
        TableName = "QuestionSummaries" 
       }; 


       s.Store(q); 
      s.Store(replicationDocument); 
       s.SaveChanges(); 
      } 

     } 
    } 

    private static void CreateRdbmsSchema() 
    { 
     var connectionStringSettings = ConfigurationManager.ConnectionStrings["Reports"]; 
     var providerFactory = DbProviderFactories.GetFactory(connectionStringSettings.ProviderName); 
     using (var con = providerFactory.CreateConnection()) 
     { 
      con.ConnectionString = connectionStringSettings.ConnectionString; 
      con.Open(); 

      using (var dbCommand = con.CreateCommand()) 
      { 
       dbCommand.CommandText = @"IF OBJECT_ID('QuestionSummaries') is not null 
               DROP TABLE [dbo].[QuestionSummaries] 
             "; 
       dbCommand.ExecuteNonQuery(); 

       dbCommand.CommandText = @"CREATE TABLE [dbo].[QuestionSummaries] 
             (
               [Id] [nvarchar](50) NOT NULL, 
               [VoteCount] [int] NOT NULL, 
               [Title] [nvarchar](255) NOT NULL 
             ) 
             "; 
       dbCommand.ExecuteNonQuery(); 
      } 
     } 
    } 
} 


public class Question 
{ 
    public string Id { get; set; } 
    public string Title { get; set; } 

    public List<Vote> Votes { get; set; } 
} 

public class Vote 
{ 
    public bool Up { get; set; } 
    public string Comment { get; set; } 
} 

당 Ayende의 제안 내가 Raven.Server.exe.config 파일에

<connectionStrings> 
    <add name="Reports" providerName="System.Data.SqlClient" connectionString="Data Source=.\sqlexpress2008r2;Initial Catalog=Test;Integrated Security=True"/> 

을 추가 편집,하지만 여전히 필요 문제.

답변

1

Scarpacci, 서버 app.config에 연결 문자열을 추가하지 않은 것 같습니다.

+0

나는 제안을 감사합니다. – scarpacci

+0

Raven.Server.exe.config 파일에 연결 문자열을 추가하고 시나리오를 다시 실행했지만 .... 여전히 보이지 않습니다. 내 부분에 대한 사용자 오류가 있어야하며 확인해야 할 항목이 무엇인지 확실하지 않습니다. – scarpacci