I am trying to print crystal report in PDF format , and on my local machine it’s working fine. But when I publish application to the server, it’s giving me the following error on Print button .
I am using VS2012 , SQl Server 2012, IIS 7.5 and CR version 13.5
Note: I am using integrated security so I left username and password blank. Please help.
My lines of code:
string Constring1 = ConfigurationManager.ConnectionStrings["dbRMCConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(Constring1);
conn.Open();
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("RMCChallan.rpt"));
ParameterFieldDefinitions crParameterFieldDefinations;
ParameterFieldDefinition crParameterFieldDefination;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterValues.Clear();
crParameterDiscreteValue.Value = lbl_Cno.Text;
crParameterFieldDefinations = rpt.DataDefinition.ParameterFields;
crParameterFieldDefination = crParameterFieldDefinations[0];
crParameterValues = crParameterFieldDefination.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefination.ApplyCurrentValues(crParameterValues);
rpt.SetDatabaseLogon("", "", "ADMIN-PC\\ADMIN", "dbRMC");
rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Guid.NewGuid().ToString());
Thanks for your help in advance !! :)
Stack Trace:
I am trying to print crystal report in PDF format , and on my local machine it’s working fine. But when I publish application to the server, it’s giving me the following error on Print button .
I am using VS2012 , SQl Server 2012, IIS 7.5 and CR version 13.5
Note: Using windows authentication..No username and password assigned to my database.
Server Error in '/' Application.
Database logon failed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Database logon failed.
Source Error:
Line 178: crParameterFieldDefination.ApplyCurrentValues(crParameterValues);
Line 179: rpt.SetDatabaseLogon("", "", "ADMIN-C\\ADMIN","MyDatabase");
Line 180: rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Guid.NewGuid().ToString());
Line 181:
Line 182:
Source File: e:\25jan14\WebSite1\RMC.aspx.cs Line: 180
Stack Trace:
[COMException (0x8004100f): Database logon failed.]
CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0
CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +257
[LogOnException: Database logon failed.]
CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +332
CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +310
CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +654
CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) +92
CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName) +96
CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportFormatType formatType, HttpResponse response, Boolean asAttachment, String attachmentName) +119
RMC.Button5_Click(Object sender, EventArgs e) in e:\25jan14\WebSite1\RMC.aspx.cs:180
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553594
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
We had the same issue. Ended up that we needed to install the Microsoft SQL Server 2012 Native Client (available at https://www.microsoft.com/en-us/download/details.aspx?id=29065, click Install Instructions and scroll towards the middle).
We were able to tell this because Process Monitor was showing NOT FOUND errors accessing the HKCR/SNCL11 registry key.
1.clear dataset connection.
2.set table or tables.
3.don't set datasource and dataset. becuase you sent data to crystal report.
4.refresh the reportdocument.
see this in bottom:
MyCrystalReportSource.ReportDocument.DataSourceConnections.Clear();
MyCrystalReportSource.ReportDocument.Database.Tables[0].SetDataSource(MyDataSet.Tables[0]);
MyCrystalReportSource.ReportDocument.Refresh();
MyCrystalReportSource.ReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, HttpContext.Current.Response, true, reportTitle);
Are you sure you need two slashes?
rpt.SetDatabaseLogon("", "", "ADMIN-PC\\ADMIN", "dbRMC");
Also, here is a link to msdn refrence for SetDatabaseLogon.
http://msdn.microsoft.com/en-us/library/ms226065(v=vs.80).aspx
The sample in the article is using standard security login account.
rpt.SetDatabaseLogon("limitedPermissionAccount", "1234", "ServerName", "Northwind");
You are missing user and password in the call.
It is also like you are trying to perform a trusted connection. You could try using a local ODBC connection on the web server, but it might prompt the user for AD credentials.
Good luck
In case someone else also finds this question, here's what my problem was, and how I fixed it:
I had to edit some old reports in order to add a new table to them. As part of that process I had to create a new connection and change the table locations for the pre-existing tables. All worked well until trying to deploy to the production environment, where the table locations are dynamically changed in code.
So I Googled, found this question and realised that the answer by #Chet (+1) could be a clue. And it was - I had created the new connection as Sql server native client ##.
However, instead of messing with the prod server, I remade the new connection using an OLE DB (Sql server) connection, and then it worked in all relevant places (dev, test, prod envs).
i faced a similar problem recently, it worked when i changed the locale identifier of the db connection in the report. hope this helps someone. https://stackoverflow.com/a/35545586/3013470
I battled with this problem for weeks on and off trying to deploy a Click-Once app and finally found it to be that the client computer needed the SQL Native client installed for SQL 2012; so, I had to add that to my prerequisites.
Related
I'm trying to set up a Debezium SQL Server Connector against a SQL Server instance that is controlled by DBAs at my workplace. I've been able to start up Zookeeper and Kafka Server without issue, and Kafka Connect itself works with sample Connectors, but when attempting to start a Debezium SQL Server Connector instance I've been getting the error "Couldn't obtain database name".
[2022-07-12 16:36:04,269] ERROR Stopping after connector error (org.apache.kafka.connect.cli.ConnectStandalone:117)
java.util.concurrent.ExecutionException: org.apache.kafka.connect.runtime.rest.errors.BadRequestException: Connector configuration is invalid and contains the following 1 error(s):
Unable to connect. Check this and other connection properties. Error: Couldn't obtain database name
Here is my debezium config:
name=Dbz-SqlServer-connector
connector.class=io.debezium.connector.sqlserver.SqlServerConnector
database.hostname=MyDbHost
database.port=1433
database.user=MyUsername
database.password=MyPassword
database.dbname=MyDatabase
database.server.name=MyDbHost
table.include.list=dbo.CdcTest
database.history.kafka.bootstrap.servers=localhost:9092
database.history.kafka.topic=dbhistory.CdcTest
I've tried this in a .properties file passed to a standalone Connect instance, and as a JSON POST to a distributed Connect instance. I have tried all of the same steps on both my local Windows machine as well as on a linux VM, with the same results.
Confluent and Docker are not options for me in this situation.
for SQL Server login credentials, I am using a local account on the SQL Server instance that does have access to the database in question. I found the source code for debezium's connectors on their github and was able to find that specific error message within the code:
private static final String GET_DATABASE_NAME = "SELECT name FROM sys.databases WHERE name = ?";
...
public String retrieveRealDatabaseName(String databaseName) {
try {
return prepareQueryAndMap(GET_DATABASE_NAME,
ps -> ps.setString(1, databaseName),
singleResultMapper(rs -> rs.getString(1), "Could not retrieve exactly one database name"));
}
catch (SQLException e) {
throw new RuntimeException("Couldn't obtain database name", e);
}
}
I'm not completely familiar with Java but it appears that basically something is going wrong when the connector is trying to run "SELECT name FROM sys.databases WHERE name = 'MyDatabase'". When I run this against the database myself, logged in with the same account I'm using, it seems to work just fine, so I'm really not sure where to go from here. It is fair to say that since I'm not in full control of the SQL Server environment that I'm using, there may be some permissions issues that I'm not aware of, but from what I'm able to test it seems like it should be working.
I would greatly appreciate any help at all, whether just suggestions on settings/configs to check or a full-blown solution.
Thank you!
Update: I've built a simple console app to run that sys.databases query against MyDbHost, master database, as the relevant account, and it's working just fine so I feel like that confirms that my connection info is correct and account permissions are also correct. Seems like this is an issue within the Debezium connector.
It turned out that my problem was a mistake in the connector's config setting. I misunderstood which specific pieces of data to put into database.hostname and database.server.name, and one I corrected those fields the connector works.
I'm deploying a web application using IIS and ASP.NET CORE.
I setup a "appsetting.json" file that include a connection string to sql server.
So far, any variation I've tried didn't work.
The strange thing about it, is that it works perfectly on a my local machine, but when I deploy it and send an HTTPPost, log file says there's an error using connection to database on server.
Well, I tried all variations I could think of.
Current connection string generated by Visual Studio is :
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Swap;Integrated
Security=True;Connect Timeout=30;Encrypt=False;
TrustServerCertificate=False;
ApplicationIntent=ReadWrite;MultiSubnetFailover=False
I've tried changing the "Integrated Security" to False.
I've tried to replace it with User ID and password (of "sa" user).
I've tried adding a "Initial Catalog" property and set it to my database.
I'm preety sure the startup of the app is fine, because when I try to send a GET request to the main page, everything seems fine.
When I send a POST request and asks the DBcontext to Add and SaveChanges, it shows this error :
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database 'Swap' on server
'(localdb)\MSSQLLocalDB'.
This is the function that I tried to send a HTTPPost request to:
byte[] j = new byte[(int)Request.ContentLength];
Request.Body.Read(j, 0, (int)Request.ContentLength);
string str = Encoding.ASCII.GetString(j);
TokenSet tokenSet = new TokenSet {Token = str };
sqlTokensetData.Add<TokenSet>(tokenSet);
sqlTokensetData.SaveChanges();
HttpClient notificationSender = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,
"https://fcm.googleapis.com/fcm/send");
request.Headers.TryAddWithoutValidation("Authorization", "key="
<somekey>);
request.Headers.TryAddWithoutValidation("Sender", "id=<id>");
Message pushNotification = new Message(new string[] { str }, "Success!"
<somestring>);
request.Content = new
StringContent(JsonConvert.SerializeObject(pushNotification)
,Encoding.UTF8,"application/json");
HttpResponseMessage output = await notificationSender.SendAsync(request);
Log file error:
https://anotepad.com/notes/9a8jxa
I hope that the "str" string will be inserted to the database.
Thank you.
Well, Basicly, Thanks to the comments above I've managed to solve it.
What you need to do if you come by the same error:
1.Download SQL Server Express -
https://www.microsoft.com/en-us/sql-server/sql-server-editions-express as said above.
and configure the SQL Server however you see fit.
2.Configure sa user, set password and enable it.
3. If SQL Authentication doesn't work, then in Microsoft SQL Server Management Studio -> Right-click the server -> Properties -> Server Authentication -> Change to SQL Server and Windows Authentication
4. Change connection string to :
Data Source=;Initial Catalog=User ID=sa;
Password=;
Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;
ApplicationIntent=ReadWrite;MultiSubnetFailover=False
It worked for me.
I Have strange problem when i tried to publish my asp.net mvc application to my local (pc) iis with "Always Encrypted" Enabled.
My application keep timeout when i tried to access database using EF6 at local IIS (not express) :
But if i tried to access & debug my asp.net mvc app using Visual Studio 2017, database with 'always encrypted enabled' can be accessed perfectly without timeout.
And also i can access it with SQL Management Studio without problem.
Both (SMSS & ASP.NET web config) using this configuration.
Column Encryption Setting=enabled;
Note : I'm using ASP.NET MVC 5 & EF 6, SQL Server 2016 Developer Edition.
Sorry for my bad english.
UPDATED :
I have tried using .NET Framework Data Provider to see if there's any clue that'll help me solving this issue, Using following code :
var context = new TestDevEntities();
StringBuilder sb = new StringBuilder();
string connectionString = context.Database.Connection.ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(#"SELECT [id],[name],[CCno] FROM [TestDev].[dbo].[testEncCol]", connection, null, SqlCommandColumnEncryptionSetting.ResultSetOnly))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
sb.Append(reader[2] + ";");
}
}
}
}
}
above code show me this error :
Now, with this kind of error i know i exactly i must do :)
Change the identity of application pool to the 'user' who previously generated the certificate.
Export currentuser cert (used by always encrypted) and import to the user that you want to use as application pool identity.
Now its worked!
EF should throw some kind of error as clear as .NET Data Providers do, instead of timeout failure that really confuse me #_#
UPDATED (1) :
Now the question is how to use it (Certificate) with default ApplicationPoolIdentity instead of custom account?
UPDATED (2) :
I have done what jakub suggest, but still no luck.
Thanks
One way (could be the only way) to use the DefaultAppPool identity instead of a custom (user) account is to store the certificate in the Local Machine certificate store (not Current User).
Once you create a certificate in the Local Machine certificate store, you need to grant DefaultAppPool access to the cert. You can do that using Microsoft Management Console (and the plugin for Local Computer certs):
Right click on the cert, select All Tasks > Manage Private Keys.
Click Add.
Set location to your computer (not your domain).
Enter IIS AppPool\DefaultAppPool as the object name.
Click OK twice.
I have the following code snippet:
SqlConnection sr = new SqlConnection(this.strConnection);
sr.Open();
Where connection string is:
Data Source = localhost;Initial Catalog=UIB_IS;Persist Security info=True;User ID=USR;Password=PSW;
(I have removed the user name and password from above for purpose of this question - I have double checked the password has not expired and is still the same.)
Every time I try to open the connection I get a failed exception.
I have also tried using the Microsoft.SqlServer.Management.Smo.Server() object with a string connection as well as a ServerConnection object. With the server connection object using a string and SQLConnection object.
None seem to be working.
Within the connection string I have tried the syntax ServerName\SQLSERVERNAME, 127.0.0.1 as well as localhost as you can see above.
Previously this code has been working over the last 6 months using the 'ServerName\SQSERVERNAME' syntax in the connection string on a Microsoft.SqlServer.Management.Smo.Server() object.
This last week.....no longer works.
No System updates have been applied. The DB and SQL User exist with the appropriate permissions set as were before. SQL Server still has allow remote connections set to allow.
The server firewall is also off (Development machine)
I cannot understand why it would suddenly stop working?
Anyone have any ideas?
Thanks in advance.
Be sure that your Sql Server allow remote connections. You can check its status under Sql Server Surface Area Configuration --> Surface Area Configuration for Services and Connection.
This should be painfully simple, but I cannot come up with a working connection string for a local copy of SQL Server 2008 using Windows Authentication. I've tried using the Data Link Properties tool to create a connection string and it has no problems connecting, but when I copy paste the generated string into my ADODB.Connection object's ConnectionString property I get all sorts of fun and different errors.
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=climb4acure;Data Source=(local);"
Microsoft OLE DB Service Components (0x80040E21)
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
I've tried a variety of similar connection strings but I cannot find one that will work with Windows Authentication. Can someone point me in the right direction?
Thanks!
Here's an easy way to generate connection strings that work.
Right-click an empty spot on the desktop and choose NEW, TEXT DOCUMENT from the context menu
Save it with a .udl extension, and click yes when it asks are you sure.
Double-click the new udl file you just created. It will open a dialogue. Go to the Provider tab, and choose the appropriate provider.
Go to the Connection tab and fill in the server name and database name, and choose NT authentication (or use a specific username and password, which is SQL authentication). Now click Test Connection. If it works, you're ready to click OK and move on to the final step. If it doesn't you need to resolve permission issues, or you've mis-typed something.
Now right-click the file on the desktop and open it in notepad. It will display the connection string that you can copy and paste to wherever you need it.
I assume you have the 2008 Native Client installed? Also, I noticed that you're missing the "provider" tag at the beginning - do you have any more luck with this one:
Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=climb4acure;Data Source=(local);
Have you had a look at connectionstrings.com? They are a pretty good reference (but, in my experience, they don't work too well in the Google Chrome browser).
Works absolutely fine:
"Provider=SQLNCLI;Server=xxxxxxxx;uid=sa;pwd=xxxxxx;database=xxxxxx;"