Crystal Reports asks password in Client systems - crystal-reports

This is the Login Info Method
private void SetLogonInfo()
{
try
{
LogInfo.ConnectionInfo.ServerName = "ServerName";
LogInfo.ConnectionInfo.UserID = "UserID";
LogInfo.ConnectionInfo.Password = "Password";
LogInfo.ConnectionInfo.DatabaseName = "DataBase";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
To create report I used this code
crystalReportViewer1.ReportSource = null;
rptdoc = new ReportDocument();
rptdoc.Load("REPORTS\\TC.rpt");
crystalReportViewer1.SelectionFormula =selectionFormula;
crystalReportViewer1.ReportSource = rptdoc;
rptdoc.Database.Tables[0].ApplyLogOnInfo(LogInfo);
It works well in server system, but if I use this in client systems, it asks for username and password. I'm using Crystal Reports 10. Moreover sometimes it asks for Username password in server system also. How to resolve this?

You're doing things in the wrong order. You need to do the login programmatically BEFORE you load the report on the viewer.
Additionally, I cannot stress enough that you need to test your program on the server machine and a test client machine before you release it to users.

The reason for this error is wrong username, password.
Check username, password and use the code below:
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
//This is for Access Database
crConnectionInfo.ServerName = "" + "" +Application.StartupPath + "\\Database.mdb"; //access Db Path
crConnectionInfo.DatabaseName = "" + "" + Application.StartupPath + "\\Database.mdb";//access Db Path
crConnectionInfo.UserID = "ADMIN";
crConnectionInfo.Password = Program.DBPassword; //access password
//This is for Sql Server
crConnectionInfo.UserID = Program.Severuser; //username
crConnectionInfo.Password = Program.Password;//password
crConnectionInfo.ServerName = Program.server;//servername
crConnectionInfo.DatabaseName = Program.database;//database
string path = "" + Application.StartupPath + "\\supportingfiles\\Invoice.rpt";
cryRpt.Load(path);
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
cryRpt.SetParameterValue("invoiceno", Program.billno);
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();

Related

can not connect Azure SQL with Azure AD user in Azure

I have a powershell script used to query Azure SQL database with Azure AD user. I can run the poweshell script on my local machine. But when I host the powershell script on Azure function, I always get the error : keyword not supported: 'authentication'
My script
$Username = “”
$Password = “”
$Port = 1433
$cxnString = "Server=tcp:$serverName,$Port;Database=$databaseName;UID=$UserName;PWD=$Password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;Authentication=Active Directory Password"
$query = ''
Invoke-Sqlcmd -ConnectionString $cxnString - Query $query
According to my test, now we can not implement it with PowerShell in Azure Function. Now we can implement it with .Net Core Function. We need to package Microsoft.Data.SqlClient
For example
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
string userName = "<>";
string password = "<>";
string server = "<>.database.windows.net";
string database = "test";
builder.ConnectionString = "Server=tcp:" + server + ",1433;Initial Catalog=" + database + ";Authentication=Active Directory Password;User ID=" + userName + ";Password=" + password + ";MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;";
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
connection.Open();
string sql = "SELECT * FROM StarWars";
using (SqlCommand command = new SqlCommand(sql, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
log.LogInformation(reader.GetString(2));
}
}
}
}

How to Hash Submitted passwords using JdbcRealm in Shiro?

I've created an application and been using Shiro for the authentication.
I've followed most of the guides and also some of the posted questions here regarding shiro and Jdbc Realm.
Here is my shiro.ini file:
[main]
authc.loginUrl=/jsp/loginForm.jsp
authc.successUrl=/test/successUrl.jsp
authc.rememberMeParam = login-remember-me
logout.redirectUrl=/index.jsp
hashService = org.apache.shiro.crypto.hash.DefaultHashService
hashService.hashIterations = 500000
hashService.hashAlgorithmName = SHA-256
hashService.generatePublicSalt = true
hashService.privateSalt = someBase64EncodedSaltValue
realm = org.apache.shiro.realm.jdbc.JdbcRealm
realm.permissionsLookupEnabled = false
realm.authenticationQuery = SELECT password FROM userTable WHERE username = ?
ps = org.apache.shiro.authc.credential.DefaultPasswordService
ps.hashService = $hashService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $ps
jof = org.apache.shiro.jndi.JndiObjectFactory
jof.resourceName = java:comp/env/jdbc/theResourceName
jof.requiredType = javax.sql.DataSource
jof.resourceRef = true
realm.dataSource = $jof
realm.credentialsMatcher = $pm
securityManager.realms = $realm
and i'm using the following code in Java to save the password in the database:
DefaultHashService hashService = new DefaultHashService();
hashService.setHashIterations(500000);
hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
hashService.setPrivateSalt(new SimpleByteSource(
"someBase64EncodedSaltValue")); // Same salt as in shiro.ini, but NOT
// base64-encoded.
hashService.setGeneratePublicSalt(true);
DefaultPasswordService pwService = new DefaultPasswordService();
pwService.setHashService(hashService);
this.password = pwService.encryptPassword(password);
Everything looks good and is saving as expected but the problem is when I am logging in. I've traced the execution to JdbcRealm.class and I've seen that the value compared is the "raw string password" and the encrypted password from the database.
Did I miss any step configuring?
To use Salted its better to have seperate salt for every user. So store that salt in database. SEE
Now,
Extend org.apache.shiro.realm.jdbc.JdbcRealm like:
package common.shiro;
import org.apache.shiro.realm.jdbc.JdbcRealm;
public class JDBCSaltedRealm extends JdbcRealm {
public JDBCSaltedRealm() {
setSaltStyle(SaltStyle.COLUMN);
}
}
In shiro.ini:
credentialsMatcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
credentialsMatcher.hashAlgorithmName=SHA-256
credentialsMatcher.storedCredentialsHexEncoded = false
credentialsMatcher.hashIterations = 500000
credentialsMatcher.hashSalted = true
realm = common.shiro.JDBCSaltedRealm
realm .permissionsLookupEnabled = true
realm .authenticationQuery = SELECT password,salt FROM userTable WHERE username = ?
realm .dataSource = $jof
realm .credentialsMatcher = $credentialsMatcher
securityManager.realm = $realm

How to send outlook mails without opening outlook in PC by testcomplete

i am trying to send outlook mail using vb script language in testcomplete. i am able to send but if the outlook is opened in my PC then only mail will be sent and if the oulook is not opened in my pc,my mail will not be sent untill opening the outllok even after executing this script
here is my code:
Function SendMail
Dim objOutLook, NamespaceMAPI,objNewMail, fso, SendReceiveControls
Dim strTo,strCc ,strBcc ,strSubject, AccountName,strAttachmentPath
strSubject="test"
strTo=yyy#yy.com
strCc=XXX#XX.com
strBcc =zzz#zzz.com
strAttachmentPath="c:\text.txt"
If strTo ="" and strCc = "" and strBcc =""Then
Exit function
ElseIf strSubject =""Then
Exit function
End If
Set objOutLook = CreateObject("Outlook.Application")
Set NamespaceMAPI = objOutLook.GetNamespace("MAPI")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objOutLook.DisplayAlerts =True
objNewMail.TO = strTo
objNewMail.CC = strCc
objNewMail.BCC=strBcc
objNewMail.Subject = strSubject
objNewMail.Body = strMsg
If strAttachmentPath <> "" Then
Set fso =CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strAttachmentPath) Then
objNewMail.Attachments.Add(strAttachmentPath)
objNewMail.display
Else
msgbox "Attachment File Does not exists"
End If
End If
AccountName="XXXXXX#XXXX.com"
' Finding the "Send/Receive" control
Set SendReceiveControls = NamespaceMAPI.GetDefaultFolder("Inbox")._
CommandBars("STANDARD").Controls("Send/Receive")
Set Item = Nothing
'msgbox "send:"&SendReceiveControls.Controls.Count
For I = 1 To SendReceiveControls.Controls.Count
If InStr(SendReceiveControls.Controls(I).Caption, AccountName) > 0 Then
Set Item = SendReceiveControls.Controls(I)
'msgbox "send1"&SendReceiveControls.Controls(I)
Exit For
End If
Next
' Executing the "Send/Receive" action
Item.Controls(1).Execute()
objOutLook.Quit
''''''' Releasing objects '''''''
Set objOutLook =Nothing
Set objNewMail = Nothing
Set fso = Nothing
End Function
please suggest me how to handle this...thanks in advance
Do you really need to send it with outlook?
I use this javascript code to send the email, then, in outlook, you just need to mark it as not spam, otherwise, it goes directly to the spam inbox
function SendEmail(mFrom, mTo, mSubject, mBody, username, password)
{
var i, schema, mConfig, mMessage;
try
{
schema = "http://schemas.microsoft.com/cdo/configuration/";
mConfig = Sys.OleObject("CDO.Configuration");
mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingExchange
mConfig.Fields.Item(schema + "smtpserver") = "STMP SERVER ADDRESS HERE"; // SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25; // Port number
mConfig.Fields.Item(schema + "smtpauthenticate") = 1; // Authentication mechanism
mConfig.Fields.Item(schema + "sendusername") = username; // User name (if needed)
mConfig.Fields.Item(schema + "sendpassword") = password; // User password (if needed)
mConfig.Fields.Update();
mMessage = Sys.OleObject("CDO.Message");
mMessage.Configuration = mConfig;
mMessage.From = mFrom;
mMessage.To = mTo;
mMessage.Subject = mSubject;
mMessage.HTMLBody = mBody;
mMessage.Send();
}
catch (exception)
{
Log.Error("E-mail cannot be sent", exception.description);
return false;
}
Log.Message("Message to <" + mTo + "> was successfully sent");
return true;
}
Try objNewMail.Body.Send instead of trying to execute the send and receive button. Here's a simple example:
Function SendMail()
Dim objOutlook, objNewMail
Set objOutLook = CreateObject("Outlook.Application")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objNewMail.TO = "myrecip#test.com"
objNewMail.Subject = "test"
objNewMail.Body = "test"
objNewMail.Send
End Function

Error Opening Crystal Report in ASP.NET

i am trying to open a crystal report in my website but its giving an error
Here is the code i have tried
protected void report_view(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("C:\\Report1.rpt");
crConnectionInfo.ServerName = "local";
crConnectionInfo.DatabaseName = "MyEmployees";
crConnectionInfo.UserID = "MYLAPTOP\\HOME";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
and here is the error shown in CrystalReportViwer
Failed to open the connection. Failed to open the connection. Report1 {1222DD0B-C24E- 4E66-8EE1-7ED7F5F0D6B4}.rpt
i am using visual studio 2010 with Crystal Reports 11
It seems that you are missing a password when declaring the connection details. Try adding it:
crConnectionInfo.ServerName = "local";
crConnectionInfo.DatabaseName = "MyEmployees";
crConnectionInfo.UserID = "MYLAPTOP\\HOME";
crConnectionInfo.Password = "Password"; //Swap with real password of course
Ensure that all file paths and file names are also correct.
Alternatively you can look into the SetDataBaseLogon() method

Classic ASP emails not working with Outlook SMTP relay

I am trying to get the classic ASP page working with Outlook (Microsoft Web Email) SMTP relay. I am getting the following error :
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
My code looks like
dim objEmail
Set objEmail = Server.CreateObject("cdo.message")
objEmail.To = list
objEmail.From = "xyz#abc.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
objEmail.Configuration.Fields.Update
objEmail.Send
I tested with GMAIL and this thing snippet works fine with it. I guess I am missing something in configuration of Outlook SMTP
Here is an example that does work. Make sure that the account you use has a mailbox, and the from adress is indeed the account adress.
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
var msg = new MailMessage();
msg.Subject = "Hello";
msg.Body = "Hello Sir";
msg.From = new MailAddress("no.reply#contoso.com");
msg.To.Add("user#contoso.com");
var client = new SmtpClient("smtp.outlook.office365.com");
client.Port = 587;
client.Credentials = new NetworkCredential("no.reply#contoso.com", "******");
client.EnableSsl = true;
client.Send(msg);