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

Teradata connection using Teradata.Net.Data.Provider Not working

$
0
0

Hi,

I have an MVC 5 application. I am new to MVC and Teradata.

I am trying to connect to a Teradata database using Teradata.Net.Data.Provider.

I have installed ODBC driver for Teradata (.NET Data Provider for Teradata 15.11.0.1).

I also installed Teradata.Net.Data.Provider in my project using NuGet package manager.

When I am trying to connect to Teradata I am getting the following error while opening the connection:

“An exception of type 'Teradata.Client.Provider.TdException' occurred in Teradata.Client.Provider.dll”

Message:

{"[.NET Data Provider for Teradata] [115006] Could not resolve DataSource=[MyDSNName] to an IP Address."}

Stack Tace:

   at Teradata.Client.Provider.WpTcpTransport.WpHost.<AddressList>d__0.MoveNext()

   at Teradata.Client.Provider.WpTcpTransport.Connect(Int32 timeout)

   at Teradata.Client.Provider.WpSession.OpenTransport(Int32 connectionTimeout)

   at Teradata.Client.Provider.WpSession.Open(Int32 connectionTimeout, String password)

   at Teradata.Client.Provider.ExeContext`3.Open(Int32 timeout, String password)

   at Teradata.Client.Provider.Connection.Open(UtlConnectionString connectionString, UInt32 timeout)

   at Teradata.Client.Provider.ConnectionPool.CreateConnection(UInt32 timeout)

   at Teradata.Client.Provider.ConnectionPool.GetConnectionFromPool(Object owningObject)

   at Teradata.Client.Provider.ConnectionFactory.GetConnection(Object owningObject, UtlConnectionString connStr)

   at Teradata.Client.Provider.TdConnection.Open()

   at UM.Models.UMDbContext.GetDelegates() in C:\Users\userId\Documents\UM Audit\SourceCode\AuditApps\UM\Infrastructure\DbContext.cs:line 48

   at UM.Controllers.HomeController.Home() in C:\Users\userId\Documents\UM Audit\SourceCode\AuditApps\UM\Controllers\HomeController.cs:line 21

   at lambda_method(Closure , ControllerBase , Object[] )

   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)

   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)

   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)

   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)

   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

Here is my code:

            TdConnectionStringBuilder connectionStringBuilder =newTdConnectionStringBuilder();

            connectionStringBuilder.DataSource ="MyDSNName";

            connectionStringBuilder.Database ="MyDatabase";

            connectionStringBuilder.UserId ="MyUserName";

            connectionStringBuilder.Password ="MyPassword";

            connectionStringBuilder.AuthenticationMechanism ="LDAP";

             using (TdConnection cn =newTdConnection())

            {

                cn.ConnectionString = connectionStringBuilder.ConnectionString;

                cn.Open();

                 TdCommand cmd = cn.CreateCommand();

                cmd.CommandText ="SELECT DATE";

                 using (TdDataReader reader = cmd.ExecuteReader())

                {

                    reader.Read();

                   DateTime date = reader.GetDate(0);

                }

            }

I am using the same DSN for connecting to Teradata through Teradata SQL Assistant and there it does work.

The reason why I didn't use Entity Framework for database connection is I am not able to Choose ODBC as data provider in the choose data source wizard while adding ADO.Net Entity data model.

It will be of great help if you can help me connect to Teradata database via either of the ways.

A million thanks in adnvance.

Thanks & Regards,

Dennis Thomas


Connecting to webDAV

$
0
0

Hi, 

I am looking to access WebDAV through C# or Navision , in order to do some transaction , Like copy , delete, move. kindly help me on this.

Process.Start running a vbs script fails. However When script runs manually or from batch file is successful

$
0
0

I'm scratching my head here. I have a VBS script which accessing a COM object CPAPPLET.CPAppletMgr.  All the script is doing is getting the number of actions available in the SCCM Client.   I'm working on an C# application which will run various scripts to perform various functions, etc.  When I run the script manually from DOS or from a batch file, it returns the value.  When I try to run this in a Process.Start.  It fails with the following error:

VBScript Runtime error: ActiveX Component can't create object:  'CPAPPLET.CPAppletMgr'

Code in my app:

var cmd = @"C:\Users\ehubba\Desktop\ClientHealth\SCCMClientActionCount.vbs";
var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    Arguments = cmd,
                    FileName = @"C:\Windows\SysWOW64\cscript.exe",
                    CreateNoWindow = false,
                    UseShellExecute = false,
                    Verb = "runas",
                    WindowStyle = ProcessWindowStyle.Normal                  

                }

            };         


try

            {

                process.Start();

                process.WaitForExit();

                System.


Console.WriteLine(process.ExitCode);

                process.Close();

            }

catch (Exception ex)

            {

                System.


Console.WriteLine(ex.ToString());

            }


I'm stumped and can't proceed until I figure this out.





Can I use lambda with this code?

$
0
0

Hi !

Is it possible to use lambda to replace the inner foreach loop?

        public void GetCustomPublisherNames(int iCustomAssignmentIndex, out string[] aryStrPublisherNames, bool bSort)
        {
            List<string> listPublisherNames = new List<string>();

            foreach (KeyValuePair<string, Publisher> pkvPair in _PublisherData.PublisherDictionary)
            {
                foreach(CustomAssignment pAssignment in pkvPair.Value.Assignments.CustomAssignments)
                {
                    if(pAssignment.Index == iCustomAssignmentIndex)
                    {
                        listPublisherNames.Add(pkvPair.Value.Name);
                        break;
                    }
                }
            }

            if (bSort)
                aryStrPublisherNames = listPublisherNames.OrderBy(p => p).ToArray();
            else
                aryStrPublisherNames = listPublisherNames.ToArray();
        }

Thanks.

Cancel Print Job via GDI

$
0
0

I am trying to cancel print job if there is error via C# API as follows.

         public override void OnEndPrint(PrintDocument document, PrintEventArgs e)
        {
            if (isException)
            {
                e.Cancel = true;
            }
            base.OnEndPrint(document, e);
        }

I find that the underlying API is GDI AbortDoc
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162456(v=vs.85).aspx

The documentation mentions that "If Print Manager was used to start the print job, calling AbortDoc erases the entire spool job, so that the printer receives nothing. If Print Manager was not used to start the print job, the data may already have been sent to the printer. In this case, the printer driver resets the printer (when possible) and ends the print job."

What is "Print Manager"? How can I know if my print job is used Print Manager to start? 

WebAPI IP Address security implementation.

$
0
0
Am looking for a way to implement an IP Address security implementation for the login part on the WebAPI for the Desktop login application. The Web API will only Authenticate IP Address on a list or Database by implementing a program that checks if the database or Text File has been altered, and share with me the IP Addresses that have been Altered. Do you think that this is the best way to eradicate DOS Attacks, and other database hacking attacks? The database can be prevented from Adding users or changing the passwords by not allowing users not to perform any kind of password or login change unless they send a text message. So, mobile numbers, will be an integral part of manual registration after payment. Where can one submit such applications for review by experts for a fee. Upwork is not my cup of coffee. I was banned from using the site.

Trying to search 2 columns in a excel file and update 2 other columns if the search finds key words

$
0
0

So I'm trying to build a small parser that I can provide key words(not hardcoded, at least not after I'm done), during dev I can setup an array of the keywords as at the moment there are only 6 keywords.. I setup a small winform app to pull in the .xlsx file and it loops thru no problem. But what I really need to be able to do is the following

The file has 5 columns, we need to search thru 2 of those columns("B" and "E" or the entire sheet if its easier that way) and find any of the 6 keywords, anytime it finds the key words I need to update columns "F" and "G" based on what it finds, so not only does it need to search for the words, then I need to parse out the data associated with those keywords..

Example:

A           B                              C        D                E                              F        G
1234      Large 4pk of Socks    234     My Socks     PackSize = 4 Pack     4        Pack
2345      Small24pkofshirts      894     My Shirts     PackSize = 24 Pack   24      Pack

Since the data is not always this clean I need to be able to identify the keywords and then pull out just the bits I need. Column B is a freeform text field, so if someone decided to enter everything with no spaces, then it will look like record 2, column E is a little more unique and should be easier to look thru.

So since column B is a general text field , how can I search for any of the key words (Pair, Pack, PK, OZ, Ounces, Grams and PackSize) in both columns "B" and "E", when it finds any of the key words, I need to populate column "F" with the numerical value associated with the keyword and then populate column "G" with the keyword.

What are my best options to find the line and update the 2 columns with the parsed data?


Securing client/server connection

$
0
0

Hi all,

I wrote a client/server program. Connection is an internet based. When a client connects to the server, I need to make sure that he/she is an authorized client. Clients are using Windows and the server is using Ubuntu. The software is a combination of C# and Java.

The best solution I could come up with is to require each client to use a static IP and on the server I configure Ubuntu to block all but those static IPs. I would prefer not to ask clients to obtain static IPs since it involves extra cost, time and effort.

Is there an alternative solution that doesn't involve third party tools?

Using simple user name and password is not a good solution as this information could be shared between authorized and unauthorized users.

Thank you.


new project

$
0
0
I cant create any new project if i create  its see an error ' object reference not set an object'

About C#

$
0
0
What are the procedural programming solutions in context to c# programming??

Get Line number where exception has occured

$
0
0

I am working on a program and have almost 2000 lines of code. I had used several Try Catch for exception handling like -

try {
	lblAppVersion.Text = "Version " + My.Settings.AppVersion;
} catch (Exception ex) {
	Interaction.MsgBox(ex.Message);
}

Now, when I load the program, I am getting the following error -

When I click OK, my program loads normally. Even though I don't have any code on form load event despite I am getting this error.

Now I don't know which code is producing this exception, is there any way to find out exact location of the code that is creating this error, using line numbers or something ? Can somebody help me out ?


C# code via SCOM SDK returning null in alert.Parameters, but powershell works

$
0
0

When calling alert.Parameters from SCOM SDK return values are null (empty list), but when same function is used through powershell it works.   Anyone else experiencing this issue and is there a fix?

I want to replace number in two tag to double with regex in a file txt

$
0
0
I am bit confused writing the regex for finding the Text between the two delimiters <TD</TD>
and replace the text with another text in c#,how to replace?
pop.txt:
<TD>25</TD>
Result of my code
<TD>25,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00</TD>
<TG>500</TG>
<TD>60,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00</TD>
<TG>80</TG>
my code:
string text = File.ReadAllText("pop.txt");
try
{
var matches = Regex.Matches(text, pattern);
var result = (from Match m in matches select (m.Groups[2].ToString())).ToList<string>();
foreach (var item in result)
{
var a = Convert.ToDouble(item).ToString("#,##.00");
string s = String.Format("{0:0.##}", item);
//textBox4.Text += a + Environment.NewLine;
text = text.Replace(item,a);
}
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
//return;
}
File.WriteAllText("resultat.txt", text);

Can you programmatically attach a file to an existing Outlook email ?

$
0
0
I have an existing email open, I would like to programmatically attach a file to it.
Can you programmatically attach a file to an existing Outlook email ?

Handling NullReference in XML

$
0
0

I am very new to coding anything XML related.  What I am doing is using XDocument to extract a value from the response, and everything works great, except when the element is null.  Question being how can I check for a null element instead of my syntax breaking everytime?

For example, in my sytnax below if extractField isnull - the code breaks and throws a NullReferenceException each time.  What is the proper way to code for handling this situation?

public void GetData() {

         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
         receivedResponse = respStream.ReadToEnd();

XDocument xml = XDocument.Parse(receivedResponse); string extractField = xml.Element("Parent").Element("Sub1").Element("extractField").Value; }



Issues with TLS Client

My buttom crashes / freezen when i click a lot of times

$
0
0

Hello,

I am doing a project in Windows Form, and the problem is that when i click a lot of times in a button of my menu, it get a lof of Mb in the memory, the first picture is when i have done only a click, with 25MB in the memory, then in the second photo i have done almost 50 clicks, and i get more of 90 MB:       

        {
            LoginForm loginform = new LoginForm();
            sql.authenticated = true;
            authenticated.AddFormToPanel(loginform, panelcenter);
            sql.authenticated = false;
        }

^^ Is the code of the button, It generates a form, which code is:

using System;
using System.Windows.Forms;

namespace Marks_Gestionator
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        private void btConnect_Click(object sender, EventArgs e)
        {
            sql.login_sqlcmd(string.Format("SELECT password from users WHERE username = '{0}';", box_login_username.Text));
            md5.MD5encode(box_login_password.Text);
            if (sql.password == md5.passwordmd5)
            {
                MessageBox.Show("Connected.");
                sql.authenticated = true;
            }
            else
            {
                MessageBox.Show("Password is not correct.");
                sql.authenticated = false;
            }
        }
    }
}




On the other hand, my app get a crash in other part, it starts with 30MB, 


And it reports me this mistake:

ServiceModel configuration in shared .net dll - best practices

$
0
0
Hi
I was hoping someone could help with a .net dll configuration issue. I have developed a com visible .net dll that will be shared by a number of applications written .net and vb6. The dll accesses several web services and I would like to not to have to supply serviceModel configuration for each every application that references the this dll. Every attempt I have tried to separate the dll config from the calling app has simply by-passed the dll app.config. Could some tell me what is What is best practice for a shared configuration that will not be ignored at run time.

thanks in Advance

AW

How to build a model from ICollection property?

$
0
0

I have a Categories class which has a property: public virtual ICollection<Product> products. 

In the index page for products (which takes "ID" route data from clickable categories objects to display all products of the specified category ID), I need to build a model to display all the product objects. 

In the 'index' action for the productcontroller, I need to build a model that will access a category's ICollection<Product> products property to be given to the view. 

So far I have this: 

public async Task<ActionResult> Index(int? id)
        {
            var products = (await db.Categories.Where(c => c.Id == id).Select(c => c.Products).ToListAsync());

            return View(products);
        }

In the View, I have used this model type to use to display the data:

@model List<IEnumerable<ValueVille.Models.ProductViewModel>>

However, I get the error: 

Compiler Error Message: CS0411: The type arguments for method 'DisplayNameExtensions.DisplayNameFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.


NazMohammed

Suggest a DistinctValue method

$
0
0

There are many posts here and on StackOverflow about getting distinct values from a List<T>.  The intuitive approach is to use the Distinct method, such as:

List<string> names...
names = names.Distinct();

That does not work because the items in the list are reference types and so the default compare sees each item as different.  The suggested solution is to either write your own EqalityComparer or do this:

names = names.GroupBy<string>(s => s.ToString()).Select(s => s.First()).ToList(); // Yuk!

It would be nice to be able to do:

names = names.DistinctValue<string>();

or, i you have a list of more complex objects:

complexItems = complexItems.DistinctValue(x => x.distinctFld);



Craig

Viewing all 31927 articles
Browse latest View live


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