Add item to resource? Or library?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan

    Add item to resource? Or library?

    Hello group.

    Here is what I like to do.

    #1. Add ".SQL" file to project
    #2. Being able to load contents of this file into string variable.

    So, I want .SQL to be compiled into executable and being able to retreive
    contents for use inside program.

    To explain what I'm doing:
    I have app that interacts with DB. Some objects that needed is Stored
    procedures and temp tables. My idea is instead of supplying separate DB
    install - I rather have client refresh those objects on every startup. It's
    utility and this approach will work just fine.

    I can probably add this SQL like a string constants but it's PITA to manage.
    Would be much prettier if I had it in SQL files so I can edit them in SQL
    Management Studio

    Thank you,
    Ivan

  • Stanimir Stoyanov

    #2
    Re: Add item to resource? Or library?

    Ivan,

    If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make use
    of the Resources section of your Project Properties. Go there and choose the
    expando button next to "Add Resource". This will allow you to add an
    existing file (the .SQL one). Visual Studio will recognize that it as a text
    file and you can get the string contents like this:

    string sqlContents = Properties.Reso urces.{Resource/FileName};
    --
    Stanimir Stoyanov


    "Ivan" <ivan@mailgroup s.microsoft.com wrote in message
    news:773667A5-148F-47A3-BE26-9BCBFEC0BCAB@mi crosoft.com...
    Hello group.
    >
    Here is what I like to do.
    >
    #1. Add ".SQL" file to project
    #2. Being able to load contents of this file into string variable.
    >
    So, I want .SQL to be compiled into executable and being able to retreive
    contents for use inside program.
    >
    To explain what I'm doing:
    I have app that interacts with DB. Some objects that needed is Stored
    procedures and temp tables. My idea is instead of supplying separate DB
    install - I rather have client refresh those objects on every startup.
    It's utility and this approach will work just fine.
    >
    I can probably add this SQL like a string constants but it's PITA to
    manage. Would be much prettier if I had it in SQL files so I can edit them
    in SQL Management Studio
    >
    Thank you,
    Ivan

    Comment

    • Jeff Johnson

      #3
      Re: Add item to resource? Or library?

      "Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
      news:01D0805D-C821-49F4-9489-AC80492637BD@mi crosoft.com...
      If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
      use of the Resources section of your Project Properties. Go there and
      choose the expando button next to "Add Resource". This will allow you to
      add an existing file (the .SQL one). Visual Studio will recognize that it
      as a text file and you can get the string contents like this:
      >
      string sqlContents = Properties.Reso urces.{Resource/FileName};
      Most of the things I add via Add Existing File get classified as byte
      arrays, not strings (even when they're text files, like XML). Or does the
      IDE convert it for you?


      Comment

      • Stanimir Stoyanov

        #4
        Re: Add item to resource? Or library?

        I suppose the IDE does a quick check of the content to determine the best
        matching data type. Not 'catching' the text or XML files might be related to
        the encoding those files use.
        --
        Stanimir Stoyanov


        "Jeff Johnson" <i.get@enough.s pamwrote in message
        news:ubKkEEFQJH A.1164@TK2MSFTN GP02.phx.gbl...
        "Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
        news:01D0805D-C821-49F4-9489-AC80492637BD@mi crosoft.com...
        >
        >If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
        >use of the Resources section of your Project Properties. Go there and
        >choose the expando button next to "Add Resource". This will allow you to
        >add an existing file (the .SQL one). Visual Studio will recognize that it
        >as a text file and you can get the string contents like this:
        >>
        >string sqlContents = Properties.Reso urces.{Resource/FileName};
        >
        Most of the things I add via Add Existing File get classified as byte
        arrays, not strings (even when they're text files, like XML). Or does the
        IDE convert it for you?
        >

        Comment

        • Ivan

          #5
          Re: Add item to resource? Or library?

          I found another way.

          I add file, mark it to "Embed"

          Then write code:

          StreamReader streamReader = new
          StreamReader(As sembly.GetExecu tingAssembly(). GetManifestReso urceStream("Myn amespace.Folder .FileName.Exten tion"));
          string sSQL = streamReader.Re adToEnd();

          SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
          sc.ExecuteNonQu ery();

          "Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
          news:B775DF53-A0AB-4517-A9D9-CCA2CFE4F487@mi crosoft.com...
          >I suppose the IDE does a quick check of the content to determine the best
          >matching data type. Not 'catching' the text or XML files might be related
          >to the encoding those files use.
          --
          Stanimir Stoyanov
          슬롯사이트 리스트중 2025년에도 가장 중요하게 보는것은 안전성과 신뢰성입니다. 슬롯나라를 통해 안전한 온라인카지노 게임을 선택함으로써 먹튀사이트 위험에 보장을 받을 수 있습니다.슬롯나라는 10개의 먹튀검증이 완료된 안전한 온라인카지노를 추천합니다.

          >
          "Jeff Johnson" <i.get@enough.s pamwrote in message
          news:ubKkEEFQJH A.1164@TK2MSFTN GP02.phx.gbl...
          >"Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
          >news:01D0805 D-C821-49F4-9489-AC80492637BD@mi crosoft.com...
          >>
          >>If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
          >>use of the Resources section of your Project Properties. Go there and
          >>choose the expando button next to "Add Resource". This will allow you to
          >>add an existing file (the .SQL one). Visual Studio will recognize that
          >>it as a text file and you can get the string contents like this:
          >>>
          >>string sqlContents = Properties.Reso urces.{Resource/FileName};
          >>
          >Most of the things I add via Add Existing File get classified as byte
          >arrays, not strings (even when they're text files, like XML). Or does the
          >IDE convert it for you?
          >>
          >

          Comment

          • Jeff Johnson

            #6
            Re: Add item to resource? Or library?

            "Ivan" <ivan@mailgroup s.microsoft.com wrote in message
            news:99CFF515-6C43-43FF-A09B-0A7B73AE9673@mi crosoft.com...
            >I found another way.
            I consider that a "longer" way as well.


            Comment

            • Stanimir Stoyanov

              #7
              Re: Add item to resource? Or library?

              That's exactly what I was avoiding with the Resources method. But I presume
              you use .NET 1.1 (that's how I would do it there).

              The reasons I avoid this is because you have to hardcode the fully-qualified
              resource name, use kind of dirty Reflection code and StreamReaders for
              something VS can present to you in a straight-forward object-oriented way.
              --
              Stanimir Stoyanov


              "Ivan" <ivan@mailgroup s.microsoft.com wrote in message
              news:99CFF515-6C43-43FF-A09B-0A7B73AE9673@mi crosoft.com...
              >I found another way.
              >
              I add file, mark it to "Embed"
              >
              Then write code:
              >
              StreamReader streamReader = new
              StreamReader(As sembly.GetExecu tingAssembly(). GetManifestReso urceStream("Myn amespace.Folder .FileName.Exten tion"));
              string sSQL = streamReader.Re adToEnd();
              >
              SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
              sc.ExecuteNonQu ery();
              >
              "Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
              news:B775DF53-A0AB-4517-A9D9-CCA2CFE4F487@mi crosoft.com...
              >>I suppose the IDE does a quick check of the content to determine the best
              >>matching data type. Not 'catching' the text or XML files might be related
              >>to the encoding those files use.
              >--
              >Stanimir Stoyanov
              >http://stoyanoff.info
              >>
              >"Jeff Johnson" <i.get@enough.s pamwrote in message
              >news:ubKkEEFQJ HA.1164@TK2MSFT NGP02.phx.gbl.. .
              >>"Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
              >>news:01D080 5D-C821-49F4-9489-AC80492637BD@mi crosoft.com...
              >>>
              >>>If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
              >>>use of the Resources section of your Project Properties. Go there and
              >>>choose the expando button next to "Add Resource". This will allow you
              >>>to add an existing file (the .SQL one). Visual Studio will recognize
              >>>that it as a text file and you can get the string contents like this:
              >>>>
              >>>string sqlContents = Properties.Reso urces.{Resource/FileName};
              >>>
              >>Most of the things I add via Add Existing File get classified as byte
              >>arrays, not strings (even when they're text files, like XML). Or does
              >>the IDE convert it for you?
              >>>
              >>
              >

              Comment

              • Ivan

                #8
                Re: Add item to resource? Or library?

                I see your point, I changed it to do like you suggested, intellisence, etc.
                Nice.

                Now I realized that if I want to have unlimited number of scripts I can just
                name them "1.sql", "2.sql" and so on and add to resources. Then method I
                specified can be used to pull files using reflection and then it would just
                error out when all files done.

                "Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
                news:ABC6938B-F615-4FCA-AD9A-812E9476BBAE@mi crosoft.com...
                That's exactly what I was avoiding with the Resources method. But I
                presume you use .NET 1.1 (that's how I would do it there).
                >
                The reasons I avoid this is because you have to hardcode the
                fully-qualified resource name, use kind of dirty Reflection code and
                StreamReaders for something VS can present to you in a straight-forward
                object-oriented way.
                --
                Stanimir Stoyanov
                슬롯사이트 리스트중 2025년에도 가장 중요하게 보는것은 안전성과 신뢰성입니다. 슬롯나라를 통해 안전한 온라인카지노 게임을 선택함으로써 먹튀사이트 위험에 보장을 받을 수 있습니다.슬롯나라는 10개의 먹튀검증이 완료된 안전한 온라인카지노를 추천합니다.

                >
                "Ivan" <ivan@mailgroup s.microsoft.com wrote in message
                news:99CFF515-6C43-43FF-A09B-0A7B73AE9673@mi crosoft.com...
                >>I found another way.
                >>
                >I add file, mark it to "Embed"
                >>
                >Then write code:
                >>
                >StreamReader streamReader = new
                >StreamReader(A ssembly.GetExec utingAssembly() .GetManifestRes ourceStream("My namespace.Folde r.FileName.Exte ntion"));
                > string sSQL = streamReader.Re adToEnd();
                >>
                > SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
                > sc.ExecuteNonQu ery();
                >>
                >"Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
                >news:B775DF5 3-A0AB-4517-A9D9-CCA2CFE4F487@mi crosoft.com...
                >>>I suppose the IDE does a quick check of the content to determine the best
                >>>matching data type. Not 'catching' the text or XML files might be related
                >>>to the encoding those files use.
                >>--
                >>Stanimir Stoyanov
                >>http://stoyanoff.info
                >>>
                >>"Jeff Johnson" <i.get@enough.s pamwrote in message
                >>news:ubKkEEFQ JHA.1164@TK2MSF TNGP02.phx.gbl. ..
                >>>"Stanimir Stoyanov" <stoyanov@REMOV ETHIS.live.comw rote in message
                >>>news:01D0805 D-C821-49F4-9489-AC80492637BD@mi crosoft.com...
                >>>>
                >>>>If you use Visual Studio 2005 (that is, .NET 2.0) or later you can
                >>>>make use of the Resources section of your Project Properties. Go there
                >>>>and choose the expando button next to "Add Resource". This will allow
                >>>>you to add an existing file (the .SQL one). Visual Studio will
                >>>>recognize that it as a text file and you can get the string contents
                >>>>like this:
                >>>>>
                >>>>string sqlContents = Properties.Reso urces.{Resource/FileName};
                >>>>
                >>>Most of the things I add via Add Existing File get classified as byte
                >>>arrays, not strings (even when they're text files, like XML). Or does
                >>>the IDE convert it for you?
                >>>>
                >>>
                >>
                >

                Comment

                Working...