Quantcast
Channel: Visual C# forum
Viewing all 31927 articles
Browse latest View live

How to declare MWArray variable in visual studio c#?

$
0
0

Hi,

I have invoked a custom dll file into my visual studio (adding as reference). The dll contains a class that takes MWArray as input and the return type is also MWArray. I need to call that function in Visual studio. But, how do I declare MWArray type of variable?Provide me links if possible.

Thanks and Rgards,

Nidhin Nambiar


Sequential processing queu for asynchronous tasks

$
0
0

Hi,

I have a method to upload data throw API...

1. This method should not hold the UI thread till it uploads.

2. Next call should be in a queue till it completes first call..

if i use async and awit..its holding the UI thread..

Please suggest me the way to achieve the above functionality..

Thanks in Advance,

Pavan Kumar


Pavan Kumar B.V

Rocording to a DB - best approach

$
0
0

Hi there, 

I need to insert to a DB about 6 million records.

Now; the question is which approach is best:

1. Declare and open a connection once (in the Button Click event) keep it open and keep inserting from calling a class in a mutithreaded manner ?

2. Call a class in a multihreaded manner (many threads, each thread doing Open - Insert - Close) ?

Which one will be faster and more efficient. 

Kind regards, 

Peter

How to resolve the blank issue for insertAdjacentHTML()

$
0
0

We call the interface IHTMLElement, it contains the method: insertAdjacentHTML()

publicvoidTest(IHTMLElement element){IHTMLElement parent = element.parentElement;

parent.insertAdjacentHTML("beforeend",HtmlContent);}

The HtmlContent is like:

<option value="9">1                  m</option>

Then it will insert into as:
1 m
How can I resolve the problem so that to insert into as:
1               m?

PS: First, I want to use the .Replace(" ","&nbsp"), but it will replace all blank like:"<option**&nbsp**value"


exceptions

$
0
0
I use c # and I have a form and I use the adope reader component and I have this exception
Unable to instantiate the 'ca8a9780-280d-11cf-a24d-444553540000' ActiveX control because the current thread is not a single-threaded apartment (STA) thread.
What are the solutions

How to access database on a network drive in IIS

$
0
0

How to access database on a network drive in IIS.

It works fine on my local machine.. But when I deploy code to IIS it says Cannot open database

WinForms controls memory issue?

$
0
0

I am experiencing a strange "memory leak" when I am using a pushbutton to start my program.  Here is a snippet:

using Kitware.VTK

namespace vtkclasspractice
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button_test_Click(object sender, EventArgs e)
        {

               "Body of my code"

        }

     }

}

My problem is that the memory in "Body of my code" never clears until I get out of the scope of button_test_Click.  There is a loop in "Body of my code" that is supposed to re-process ~5MB of image data, but instead it seems as though the memory just adds-up each iteration. 

I know this is a problem of the pushbutton, because when I place "Body of my code" right after InitializeComponent(), within the same scope, memory does not grow.  It seems as though garbage collection does not work inside of the button_test_Click method.

Any suggestions?

C# Winforms DirectX How do I convert DirectX Audio/Video to byte array and back?

$
0
0
I'm writing a C# Winforms app that displays System.Drawing.Image images and DirectX Audio (.mp3 and .wma) and DirectX Video (.mpg and .wmv). I'm using DirectX 9.0c on a Windows 10 PC, mainly because DirectX 9.0c is the last version that'll work with C#.

So here's the code for converting audio files into a byte array:

        private byte[] Media2Bytes(string strMediaFilepath)
        {
            byte[] bytMediaInBytes = File.ReadAllBytes(strMediaFilepath);
            return bytMediaInBytes;
        }

And here's the code for converting a byte array back to audio:

        private Audio Bytes2Audio(byte[] bytBytes2Convert)
        {
            string strTempFile = Path.GetTempPath() + "MyTempFile.mp3";
            System.IO.File.WriteAllBytes(strTempFile, bytBytes2Convert);
            Audio audConvertedAudio = Audio.FromFile(strTempFile); // This is the line where the "VFW_E_UNSUPPORTED_STREAM" error occurs.
            File.Delete(strTempFile);

            return audConvertedAudio;
        }

The app crashes when I try to open a .bin file that these byte arrays are written to. The specific error I get is "VFW_E_UNSUPPORTED_STREAM" and points to the line of code in "private Audio Bytes2Audio(byte[] bytBytes2Convert)" above as indicated by the comment.

To convert the byte array back into its original audio file, I need to write it to a temp file, assign the contents of that temp file to the variable that holds the audio file and plays it. Obviously, something's not written to the temp file or the data in that temp file isn't being read correctly...or is it something else?

Problem to file created

$
0
0
Hi,
I run these
                List<string> str = new List<string>();
                List<string> list1 = new List<string>();
                bool allowappend = true;

                using (StreamReader sr = new StreamReader(@"c:/dp2/inp.txt", Encoding.Default))
                {

                    while ((line = sr.ReadLine()) != null)
                    {
                        {
                            str.Add(line);
                        }
                    }
                }

                using (StreamWriter sw = new StreamWriter(@"c:/dp2/oup.txt", allowappend, Encoding.Unicode))
                {
                    int cnt2 = 0;
                    string S0 = "";
                    line2 = "";
                    for (int i = 0; i < str.Count; ++i)
                    {
                        cnt++;
                        line2 = str[i];
                        if (line2.Length >= 1)
                        {
                            {
                                cnt2++;
                                if (str[i].IndexOf("esult") < 0)
                                    sw.WriteLine(str[i]);
                            }
                        }
                    }
                }



to copy all lines from one file into another, excluding whatever lines having 'esult' inside.

I do not know why 2nd file is becoming even bigger than 1st file. Why?

Many Thanks & Best Regards, Hua Min


How to set default printer in UWP apps

$
0
0

I have issue setting the default printer , I need to set the default printer when I run my UWP app.

using System.Runtime.InteropServices;

[DllImport("Winspool.drv")]
private static extern bool SetDefaultPrinter(string printerName);

private static void Test()
{
    // Change the default printer to XPS Document Writer
    SetDefaultPrinter("Microsoft XPS Document Writer");
}

is not working after passing to that line , the default printer is set to my previous default printer , but in console application its working.

Thanks,
NicoTing

[C#] Upload pictures with HttpClient - data not sending correctly

$
0
0

Good evening,

I know this subject has already been seen, but I didn't find any solutions to my issue. I'm trying to upload a JPG picture on my server (typical url : http://www.domain.com/upload/{idUser}) and to do that I have been using HttpClient as you can see below :

        public async Task<bool> ExecutePostPictureRequest(string endpoint, Stream stream, string name)
        {
            bool result;

            result = false;
            try
            {
                //Init client
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.ExpectContinue = true;

                //Add content
                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(CreateFileContent(stream, name, "image/jpeg"));

                //Exec request + get response
                HttpResponseMessage message = await client.PostAsync(this.url + endpoint, content);
                this.json = await message.Content.ReadAsStringAsync();
                if (message.IsSuccessStatusCode)
                {
                    result = true;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Debug - exception : " + exception.Message);
            }
            return result;
        }

Here is a private method that I use to avoid to have the fileName twice in the headers :

        private StreamContent CreateFileContent(Stream stream, string fileName, string contentType)
        {
            var fileContent = new StreamContent(stream);
            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name = "uploadfile",
                FileName = fileName
            };
            fileContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
            return fileContent;
        }

And this is the server's logs : Bad request is me using the Httpclient and the Good request is me using a simple curl command

-------------------------------------------------- Bad request Begin --------------------------------------------------
|-------------------- 1 request --------------------
| 12:46:03.817722 IP ... > eko.http: Flags [P.], seq 131614028:131614255, ack 492353908, win 32768, length 227
| E...gn@.w...V.
| 9%;)c...P..EL.X.tP...pQ..POST /upload/{userId} HTTP/1.1
| Expect: 100-continue
| Content-Length: 181
| Content-Type: multipart/form-data; boundary="8620d953-fa0c-4e20-b04f-a4741c27081f"
| Host: www.domain.com
| Connection: Keep-Alive
|-------------------------------------------------

|-------------------- 1 response --------------------
| 12:46:03.818124 IP eko.http > ...: Flags [P.], seq 1:26, ack 227, win 237, length 25
| E..A..@.?.lF%;)cV.
| 9.P...X.t..F/P.......HTTP/1.1 100 Continue
|-------------------------------------------------

|-------------------- 2 request --------------------
| 12:46:03.824090 IP ... > eko.http: Flags [P.], seq 227:408, ack 1, win 32768, length 181
| E...go@.w...V.
| 9%;)c...P..F/.X.tP....c..--8620d953-fa0c-4e20-b04f-a4741c27081f
| Content-Dis-data; name=uploadfile; filename=Cover.jpg
| Content-Type: image/jpeg
|
|
| --8620d953-fa0c-4e20-b04f-a4741c27081f--
|-------------------------------------------------

|-------------------- 2 response --------------------
| 12:46:03.830583 IP eko.http > ... Flags [P.], seq 26:260, ack 408, win 245, length 234
| E.....@.?.kt%;)cV.
| 9.P...X....F.P.......HTTP/1.1 500 Internal Server Error
| Server: nginx
| Date: Sat, 08 Oct 2016 10:46:03 GMT
| Content-Type: application/json
| Content-Length: 44
| Connection: keep-alive
| Keep-Alive: timeout=10
|
| {"error":"open : no such file or directory"}
|-------------------------------------------------
-------------------------------------------------- Bad requestEnd  --------------------------------------------------


-------------------------------------------------- Good requestBegin  --------------------------------------------------
|------------------- 1 request --------------------
| 12:49:20.192774 IP ... > eko.http: Flags [P.], seq 2331120423:2331120671, ack 2271292386, win 229, options [nop,nop,TS val 3764845 ecr 4059129475], length 248
| E..,at@.4..:.u.
| %;)c.~.P....a+......&.....
| .9rm..f.POST /upload/{userId} HTTP/1.1
| Host: www.domain.com
| User-Agent: curl/7.50.3
| Accept: */
| Content-Length: 3457
| Expect: 100-continue
| Content-Type: multipart/form-data; boundary=------------------------9d468a811aeb4aab
|-------------------------------------------------

|------------------- 1 response --------------------
| 12:49:20.193057 IP eko.http > ... Flags [P.], seq 1:26, ack 248, win 235, options [nop,nop,TS val 4059129494 ecr 3764845], length 25
| E..MMm@.?.. %;)c.u.
| .P.~.a+..........].....
| ..f..9rmHTTP/1.1 100 Continue
|-------------------------------------------------

|------------------- 2 request --------------------
| 12:49:20.239665 IP... Flags [P.], seq 248:392, ack 26, win 229, options [nop,nop,TS val 3764859 ecr 4059129494], length 144
| E...av@.4....u.
| %;)c.~.P.....a+............
| .9r{..f.--------------------------9d468a811aeb4aab
| Content-Dis-data; name="uploadfile"; filename="test.jpg"
| Content-Type: image/jpeg
|-------------------------------------------------

|------------------- 3 request --------------------
| 12:49:20.243188 IP ... Flags [.], seq 392:1840, ack 26, win 229, options [nop,nop,TS val 3764860 ecr 4059129494], length 1448
| E...aw@.4....u.
| %;)c.~.P.....a+............
| .9r|..f.......Exif..II*.................Ducky.............-http://ns.adobe.com/xap/1.0/.<?xpacket begin="..." id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CS6 (Macintosh)" xmpMM:InstanceID="xmp.iid:2B6CEE69270011E494FAC9BDB64DE453" xmpMM:DocumentID="xmp.did:2B6CEE6A270011E494FAC9BDB64DE453"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:2B6CEE67270011E494FAC9BDB64DE453" stRef:documentID="xmp.did:2B6CEE68270011E494FAC9BDB64DE453"/> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>....Adobe.d...............................................#%'%#.//33//@@@@@@@@@@@@@@@......................&.....&0#....#0+.'''.+550055@@?@@@@@@@@@@@@......,.,.."..........x................................................................A.!1..Qaq."B...2R....r.#.b.....3Ss$...............................?....S.'x.2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2c .2....q...;...........................r....I...............................(.q...;.............5.M}.4.Ug....iy.."*...W..)..A........S.........#..4..LS..KVmY..j..:).......k.Z......y).....9K.-].}K5DFxc..x;&6.
|-------------------------------------------------

|------------------- 4 request --------------------
| 12:49:20.243475 IP ... Flags [.], seq 1840:3288, ack 26, win 229, options [nop,nop,TS val 3764860 ecr 4059129494], length 1448
| E...ax@.4....u.
| %;)c.~.P...W.a+............
| .9r|..f..i5;n[.....W..Xl.....k....n.x..Z.............. ..'x........39.........|U..R..h..^...t..WDtv...n.TE.q...."..cOkOn-..).=...P.......a.mj"nZ.....Wkb...Q]....i.......r.uV.Kq..#d.......vLo.........r....I..........b&..i.fg...F........m6c...p7:.%:M=6..;k...R(........4<.G.].M...8W..^.......Mr.s....l...&&bvLl........\.....w.........t...sG7&6..g.l.>.yu=......A...............}.u.cuS......s.p.SW.D}.-h.........\..N...........C8....O...?*.+.Y..;....3...............O..Q.G.-[a.*..a.Z)..e........r....I..............m\.;...vT..9~.....L.'._..ubD.............L..w+....O.."|w|...>.s....Sr..T....@........... ..'x.........r]o.k..'.-.....6.>...WM.s....&.//.....[..t}.............l.UU4S5U8S...........&.l..-.W...y..3..?...Q.............\.....w..............-W.-.4.N.....C.-_...-......l....juS.Gr...n....&...b..U.<.}P.p...@y..Z..7/U...9.4:.msU.j.M.9..v.9.).~.W.\.....YuS--.w-.4\.h.7................. ..'x.......=,i.....T.T.":d.6...\[.L.\..ot.....j0.w|S...d.9}...<Wj...#.........<..[..;....).;%....r..I...,....a;*...i.1..1........O.6|...=.............. ..'x........v..]6..z....M..........._L..~Q..-..c..F..-?|.@(........	1..N....9.m..m_.f?B.......v.-.v.....Ta0...:.....4N.ut............\..N..........}../z.#.V.s./c_E.\..tF5W1..r.4.z4.(.G.6.L. .P..............I..5V....?..e 8..i....cd..#k.4.....<76W..x.@......... ..x.....L.1Lm..":..nC..\.STl..D.........OE......................yjlS..]..W.vNR....u.n...&bc...A......"<7c
| ..{..........\AxN.....w&.....~.Q....-.....f..Wg
|-------------------------------------------------

|------------------- 5 request --------------------
| ... Flags [P.], seq 3288:3705, ack 26, win 229, options [nop,nop,TS val 3764861 ecr 4059129494], length 417
| E...ay@.4....u.
| %;)c.~.P.....a+............
| .9r}..f..i...................Ng.....1.S....ZH8....?..]..5x{l<@...\.....w.......gdo......+....S...5..E.u.lw...|_c.................E....p.n.F.......-S..............\......qE..$.	.....g.(.j..c..d....G.z.-^...DD.Cp.....................t.m..z.....J........G.T..A.....qE..$..p.3gX .:..`...6u.......~j.......p..g....f.................#..T.......}...s....../..0...l...gY...r.l.6a.?..
| --------------------------9d468a811aeb4aab--
|-------------------------------------------------

|------------------- 5 response --------------------
| 12:49:20.576172 IP eko.http > ... Flags [P.], seq 26:247, ack 3705, win 311, options [nop,nop,TS val 4059129590 ecr 3764860], length 221
| E...Mp@.?..Y%;)c.u.
| .P.~.a+...!....7.!.....
| ..f..9r|HTTP/1.1 200 OK
| Server: nginx
| Date: Sat, 08 Oct 2016 10:49:20 GMT
| Content-Type: text/plain; charset=utf-8
| Content-Length: 41
| Connection: keep-alive
| Keep-Alive: timeout=10
|
| {"message":"File uploaded successfully."}
|-------------------------------------------------
-------------------------------------------------- Good End  --------------------------------------------------

Looks like the Httpclient is sending the data too quickly... I thank you in advance for your help and I wish you a good day / evening depends where you're from.

Best regards.

Can anyone help me how to fetch this web site data ?

$
0
0

I have the follow link:

LINK

I tried my code, cannot get the table data, because it do not have table id and with some tricky code (I think), here is my code: 

 static void Main(string[] args)
        {
            HtmlWeb webClient = new HtmlWeb();

            HtmlAgilityPack.HtmlDocument doc = webClient.Load("http://racing.hkjc.com/racing/Info/Meeting/Results/English/Local/20161116/HV/3");
            HtmlNode table = doc.DocumentNode.SelectSingleNode("//table");


                var cells = (from cell in table.SelectNodes("./tr")
                             select cell.InnerText).ToList();

            foreach (var cell in cells)

            {
                Console.Write(cell);
                Console.ReadKey();
            }

Anyone know how to get the data from this page ? and any tricky code it using ?

Thanks a lot


[UWP][C#] How append an xml data with XmlWriter

$
0
0

Hello. I'm trying to use XmlWriter for saving my data into and it's successful but, really, I want to add(appending) more data over a time.

Example: I have created xml file, like this (thank the post: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/904a66a5-05d7-4ef1-8d07-d36d81f00f61/uwpc-read-and-write-xml-file?forum=wpdevelop)

<?xml version="1.0" encoding="utf-8"?>

<Orders>

<Order>First Order</Order>

</Orders>

----------

Then I want to load my xml for adding some similar data and see, example:

<?xml version="1.0" encoding="utf-8"?>

<Orders>

<Order>First Order</Order>

<Order>Second Order</Order>

</Orders>

----------------

 Just add, without rewrite full file


what is the usage of namespace in xml ?

$
0
0

any one can discuss with a sample xml that what is the usage of namespace in xml and advantage too ?

thanks

A Debugger Bug(?)

$
0
0

Hello,

we have encountered a bug (most probably) in debugger of C#(.NET) VS 2015. The situation is following:

            // something ....

            for (int month = 1; month <= this.MainTariffInsurancePeriod * 12; month++)
            {
                ProgressionRow progressionRow = getProgressionRow(month);

 

               // something .....

               if (progressionRow.ColB_Month == 1)
                {
                    progressionRow.ColBK_BBASE = this.YearlyPremium * (LOWERED_ALLOCATION_YEAR1 + LOWERED_ALLOCATION_YEAR2);
                }

                 // continuation ....

The debugger (not runtime) bug has two demonstrations here:

1. 'month' variable is in debugger presented as value 361 thought in fact is  1 as should be.

2. progressionRow.ColB_Month property value is presented as 3770 though is 1 (program steps in into the if body)

The reason is probably related to the fact that before this code, but within in the same method there is another for loop using 'month' variable and another progressionRow declaration. The debugger shows the values from above definition.

Is there anybody who would care and fix a thing like that?

Thanks






how to validate xml when reading xml data using xml reader or xml textreader class ?

$
0
0

suppose i am reading xml document using xml reader or xml textreader class but xml reader or xml textreader class has no mechanism to validate xml. so tell me how could i validate xml against a xsd using  xml reader or xml textreader class ?

is it possible at all ?

see a sample xsd and xml sample taken from https://msdn.microsoft.com/en-us/library/ms162371%28v=vs.110%29.aspx

<?xml version="1.0" encoding="utf-8"?><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="bookstore"><xs:complexType><xs:sequence><xs:element maxOccurs="unbounded" name="book"><xs:complexType><xs:sequence><xs:element name="title" type="xs:string" /><xs:element name="author"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="name" type="xs:string" /><xs:element minOccurs="0" name="first-name" type="xs:string" /><xs:element minOccurs="0" name="last-name" type="xs:string" /></xs:sequence></xs:complexType></xs:element><xs:element name="price" type="xs:decimal" /></xs:sequence><xs:attribute name="genre" type="xs:string" use="required" /><xs:attribute name="publicationdate" type="xs:date" use="required" /><xs:attribute name="ISBN" type="xs:string" use="required" /></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:schema>
<?xml version="1.0" encoding="utf-8" ?><bookstore xmlns="http://www.contoso.com/books"><book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0"><title>The Autobiography of Benjamin Franklin</title><author><first-name>Benjamin</first-name><last-name>Franklin</last-name></author><price>8.99</price></book><book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2"><title>The Confidence Man</title><author><first-name>Herman</first-name><last-name>Melville</last-name></author><price>11.99</price></book><book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6"><title>The Gorgias</title><author><name>Plato</name></author><price>9.99</price></book></bookstore>
thanks

Windows Phone 8.1: "No suitable method found to override" - but there is one

$
0
0

Hello.

I have base class with navigation logic:

using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; using Microsoft.HockeyApp.Common; namespace View { public abstract class CommonPage : Page { private readonly NavigationHelper navigationHelper; private readonly ObservableDictionary defaultViewModel; public CommonPage() { defaultViewModel = new ObservableDictionary(); navigationHelper = new NavigationHelper( this ); navigationHelper.LoadState += NavigationHelper_LoadState; navigationHelper.SaveState += NavigationHelper_SaveState; } public NavigationHelper NavigationHelper { get { return navigationHelper; } } public ObservableDictionary DefaultViewModel { get { return defaultViewModel; } } protected virtual void NavigationHelper_LoadState( object sender, LoadStateEventArgs e ) { }

protected virtual void NavigationHelper_SaveState( object sender, SaveStateEventArgs e ) { } protected override void OnNavigatedTo( NavigationEventArgs e ) { navigationHelper.OnNavigatedTo( e ); } protected override void OnNavigatedFrom( NavigationEventArgs e ) { navigationHelper.OnNavigatedFrom( e ); } } }

And I have child class:

using Microsoft.HockeyApp.Common;

namespace View.Chats
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class ChatPage : CommonPage
    {
        public ChatPage()
        {
            InitializeComponent();
        }

        protected override void NavigationHelper_LoadState( object sender, LoadStateEventArgs e )
        {
            base.NavigationHelper_LoadState( sender, e );
        }
    }
}

But I have next error in compile time:

Error CS0115 'ChatPage.NavigationHelper_LoadState(object, LoadStateEventArgs)': no suitable method found to override

Who knows how to fix it?

Please, help :)

What is the difference between XMLReader and XMLTextReader?

$
0
0

when to use XMLReader and when to use XMLTextReader?

please tell me the difference. thanks

Xslt can be used to validate xml like xsd using c#

$
0
0

please tell me what is  Xslt and what for it is used ?

can we use xslt to validate xml like xsd using c# ?

i have seen we can validate user provided xml against xsd using c# code.....can we do the same using xslt instead of xsd ?

please guide me.

thanks

How to create custom generic factory for sql server connection

$
0
0

we have a application where we need to connect multiple database based on situation. i want to create a generic factory class where i will pass some info like <SQLLocalConnection> or <ConnectionString> and right connection string or right connection instance will be return.

string connectionString = DBConnectionFactory.GetConnectionString<ConnectionString>(Common.SQLCredentialLocal).ToString();

SqlConnection conn1 = (SqlConnection) ConnectionManager.Factory.DBConnectionFactory.GetGenericConnection<SQLLocalConnection>(ConnectionType.LocalSQLConnection);
please help me with sample code that how could i develop a generic connection factory which can manage multiple db connection. thanks


Viewing all 31927 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>