Error while uploading Excel data to SQL server 2005 - sql

I have a requirement to upload excel data into a SQL Server 2005 table. Initially I copied Excel data to a temp table and based on condition I have updated and inserted records into the SQL Server table.
Everything works fine in my local system. Same program I moved to quality server there I faced this error
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Then we installed 'Microsoft.ACE.OLEDB.12.0 provider on quality server. Now this error appearing
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data."
Kindly help me out to solve this issue.
SqlConnection con = new SqlConnection();
con = SQLManager.openSQLConnection();
string path = FileUpload1.PostedFile.FileName;
string excelConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0 Xml;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [CM_CODE],[CM_NAME],[CM_ADD1],[CM_ADD2],[CM_ADD3],[CM_ADD4],[CM_CITY],[CM_PHONE],[CM_CG_CODE],[CM_CO_CODE],[CM_EXPIRY_DATE],[CM_PINCODE],[CM_EMAIL] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
Regards,
Sathya

This is most likely a file permissions issue. Does the account that the program runs under have folder level permission to read files from the file location.
Find out which account the program runs under and then add appropriate access permissions to the folder where you upload your excel files.
If it's IIS then whichever account your app pool runs under needs write access to the folder that you upload to. Permissions can usually only be set by web server admin.
Wing

Finally i found out the solution.
I have created one folder under my application folder in Quality server.
Uploaded excel sheets wil get stored under this new folder.
and that path i am referring while updating my SQL server database.
Everything works fine now...
Thank u all for your support
Regards,
Sathya

Related

Unable to open shared SQLite database

Unable to open database file
That's the error I get when trying to open a SQLite db file that is shared, I've already allowed read/write to everyone when I shared the folder containing the db file.
I'm accessing the file using LINQPad or SQL Server Compact & SQLite Toolbox both gives me the same error.
However I can successfully work with the database using my Windows Form application with the following declaration for the connection
Dim litecon As SQLiteConnection = New SQLiteConnection("Data Source=\\10.10.10.10\SQLite\SQLiteDB.db;Version=3;Password=1;", True)
I set parseViaFramework to True

Crystal Reports failed to open the connection

I am developing a desktop software which is creating proposals and invoices. I am storing my database (MySql) in a remote server. Everything is working perfectly fine in my PC which i am using for coding.
On client machine I can add,update and delete records without any problem. But when i try to open a record in then I am facing with an error below.
I was created the report in VB.NET but when I face with the error than I opened the rpt file in Crystal Reports XI Release 2 and updated data source location, verified database and save the file. Some part of my code is :
ElseIf Me.Text = "Tekliflere Gözat" Then
Form16.Text = "Teklif Detayları:"
Dim strReportPath As String
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
strReportPath = My.Application.Info.DirectoryPath & "\Teklif.rpt"
rptDoc = New ReportDocument
rptDoc.Load(strReportPath)
rptDoc.SetDatabaseLogon("USER_NAME", "PASSWORD", "SERVER_IP", "DB_NAME")
Form16.CrystalReportViewer1.ReportSource = rptDoc
Form16.CrystalReportViewer1.SelectionFormula = "{teklif1.teklifno} =" & ListView1.SelectedItems(0).Text
Form16.CrystalReportViewer1.Refresh()
Form16.CrystalReportViewer1.RefreshReport()
Form16.Show()
Me.Close()
Could you please advise.
Thank you.
Regards
Oguz
I've found the solution. But first have to look at the casue. While connecting to a remote database via my software everthing is working fine. But when I was designing a report in CR, I created a connection in database expert menu. So that means locally I am describing to CR that where and how to connect. But when I install my software with all necessery components to the client machine CR report files searching the connection criteria and as a matter of course it can not find it in client machine.
So the solution is to install Mysql ODBC Connector to the client machine and configure it with the same settings in my PC. Or as an alternative solution, define all connection and database settings programatically in your code.
Hope this helps.

How to process excel file in vb.net without office installed

I am fairly new to VB.net and never used it for processing Office files.
Right now I have to look at Excel file and send some emails based on the data in the cells. I do not need to write anything to these files.
So far I have read quite a bit about PIAs and so far it looks that I have to design my application for particular Office version?
Is there a way to write the application which could handle files created by different versions of MS Excel?
I would like to be able to process these files without Office being installed on the computer at all, is there any way to do it?
You could use Open XML SDK 2.0 for Microsoft Office link
Don't need to install Office for getting data from excel file.
But for getting data from EXCEL fileyou have to install OLEDB driver in your local machine as well as server if you are hosted your application on server.
You can download OLEDB driver from MICROSOFT.
con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + YourEXCELFilePath + ";Extended Properties=Excel 12.0;")
con.Open()
atatable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetname = datatable.Rows(0)("table_name").ToString
excelcomm = New OleDbCommand("select * from [" + sheetname + "]", con)
adexcel = New OleDbDataAdapter(excelcomm)
adexcel.Fill(Dataset)
After this code you will get excel sheet data in dataset.
Might this code can help you to get data from excel file.
(NOTE:this code is in vb.net)
you can use
npoi
epplus
which do not require excel

System.Transactions.Diagnostics.DiagnosticTrace threw an exception

Can someone please look into this and help me out..................
I recently developed a VB.NET utility for extracting data from a DB2 table and populating an HTML report format. I am using ISeries ODBC provider for connection. The utility seems to be working fine for most users.
For some users, apparently the ones without admin privileges on their systems, this fails to work. The users are getting the below error:
System.Transactions.Diagnostics.DiagnosticTrace threw an exception
The error occurs on the connection.Open line of the DB connection section.
Dim cn = New OdbcConnection("DSN=dsnname;UID=user;PWD=pswd")
Dim cmd As New OdbcCommand(qry, cn)
cn.Open() ' here
Is there any way to resolve this without granting admin privilege to the users?
There was something wrong with my App.Config file.
I deleted it and added a new one from a new project and it fixed it for me.

I want my vb.net program with sqldb to be transferable

I'm having trouble with my vb.net program. It has a database with a SqlConnection string of:
DbConn = New SqlConnection("Data Source=ACE-DUO;Initial Catalog=db_CVSO;Persist Security Info=True;User ID=sa;Password=pwd")
I made an installer for this vb.net program but I'm having problems regarding my SQL Server connection string. It's because once I installed the program in different computer. The server name in my case (ACE-DUO) changes and the database itself cannot be located.
I know how to detach the file and attach it to vb.net program. what I'm really aiming for is that I want the connection string to change on based where the program resources were placed.
For example, if the program was installed in the C:\Program Files\MyDatabase folder, I want to make it as a part of the connection string so it would be opened in different computer.
If you don't need multiple shared access to your database you could take advandage of the LocalDB feature of Sql Server 2012.
You connection string could be changed to
DbConn = New SqlConnection("Server=(localdb)\v11.0;Integrated " & _
"Security=true;AttachDbFileName=C:\Program Files\MyDatabase\db.mdf;"
Article on LocalDB