Could You tell me how can I connect with my ms access database on my ftp server ?. I'am using this connection string:
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=ftp://ftp.myAccount.pl/myAccount.pl/dataBase/file.mdb; User Id=myUserName; Password=myPassword";
con.Open();
but wont work :(.
Here's a working example: http://www.zbconsulting.eu/?tabid=58
Contains a working demo too.
Related
I am making a micro-application using an ASP.NET Core console application and I need to retrieve a .docx file from a server database.
Any examples or suggestions?
I would recommend using the new .Net Core 3.1 Windows Service template. I recently wrote 3 small services that update database tables from other data sources. One being LDAP and the other being an Excel file available on a SFTP server.
Depending on your Use Case, I would recommend either using a connection to the SQL server using the SqlConnection class, and access the document from there, or access the document using SFTP (database server or not). There are some libraries for SFTP for .Net Core and plenty of tutorials online.
In either case, you would use your preferred connection to download the file locally as some sort of data stream most likely. Once it's downloaded locally to the server you could further utilize SFTP to send the file wherever you want on the network.
Question: Why are you downloading a docx file from a "Database" server? Is the docx file just "living" on a server that also happens to host databases on it?
Just use SqlClient to read the data as a Stream and CopyTo a FileStream. EG
var fn = "Seat Assembly.doc";
var outFile = $#"c:\\temp\\{fn}";
using (var con = new SqlConnection("server=localhost;database=AdventureWorks2017;Integrated Security=true"))
{
con.Open();
var cmd = con.CreateCommand();
cmd.CommandText = #"
select Document
from production.document
where FileName = #fn";
cmd.Parameters.Add(new SqlParameter("#fn", fn));
using (var rdr = cmd.ExecuteReader())
using (var fs = File.OpenWrite(outFile))
{
if (!rdr.Read())
{
throw new InvalidOperationException($"File not found {fn}");
}
rdr.GetStream(0).CopyTo(fs);
fs.Close();
}
}
I want to connect to the other database using LoginProperty class. I did it in two different ways:
Create a DNS system object, using loginProperty class and connect to the DB. This way it works fine.
In the other way, i wants to creat a 'Connection String' and connect to the DB. In this way i am getting an error.
ODBC operation failed. Unable to logon to the database.
[Microsoft][ODBC Driver Manager] Data source name not found and there is no standard driver.
My Connection string is:
connectionString = "Driver={SQL Server Native Client 10.0}; Server=MSS2008-term\\\\SQLServer; Database=db; user ID=sa; Password=ABC.123";
loginProperty.setOther(connectionString);
conn = new ODBCConnection(loginProperty);
What is missing in the connection string?
Try using a raw string assignment (so no \ magic):
connectionString = #"Driver={SQL Server Native Client 10.0}; Server=MSS2008-term\SQLServer; Database=db; user ID=sa; Password=ABC.123";
Some others have problems, see ODBC connection to external data.
Maybe you can create the DSN by code, see What is the simplest, most maintainable way to create a SQL Server ODBC Data Source?
I notice you have Server and Database in your connection string where I use Data Source and Initial Catalog for some reason. You can do it like this, just changing/adding relevant parameters:
public str getConnectionString() {
System.Data.SqlClient.SqlConnectionStringBuilder dbConnectionStringBuilder;
dbConnectionStringBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
dbConnectionStringBuilder.set_Item('Data Source', 'YourServer');
dbConnectionStringBuilder.set_Item('Initial Catalog', 'YourDatabase');
dbConnectionStringBuilder.set_Item('Integrated Security', true);
return dbConnectionStringBuilder.ToString();
}
I have the following code
SqlConnection conn = new SqlConnection("user id=clearpath\\user;" +
"password=Password1;server=sqldatamart;" +
"Trusted_Connection=yes;" +
"database=LENDER_LOAN_SERVICE;" +
"connection timeout=30");
SqlCommand cmd = new SqlCommand("INSERT INTO [LENDER_LOAN_SERVICE].[CMC].[Turn_Times] values('"+dateadded+"','"+username+"','"+prevtime+"','"+type+"','"+newturntime+"')",conn);
conn.Open();
which works fine when I am doing local development. However when I put the website on my IIS 6 on my computer I get the following error.
Login failed for user 'CLEARPATH\IT-CARLOSDELL$'.
Line 42: SqlCommand cmd = new SqlCommand("CMC.sp_NewDocMod", conn);
Line 43:
Line 44: conn.Open();
Line 45:
Line 46: SqlDataReader reader = cmd.ExecuteReader();
with an error on line 44.
It seems its changing the connection string from clearpath\cpereyra to clearpath\IT-CARLOSDELL$
My computer name is IT-CARLOSDELL
any ideas on how to fix this?
Thanks
Sounds like your application pool is using 'LocalSystem' as pool identity.
You need to do one of the following:
Give permissions in SQL for the CLEARPATH\IT-CARLOSDELL$ account
Change the identity on the application pool to one with permissions in the DB (Perhaps clearpath\cpereyra)
Set up authentication on your site to impersonate the user who connected to the site and has rights in the SQL DB.
Remove Trusted_Connection=yes from your connection string.
Which one you pick depends on the approach you use to secure your site.
BTW: It is not changing the connection string. It is using that account because you have Trusted_Connection=yes. It is using the account the ASP.NET worker process is running under to try to connect to the database.
Remove the Trusted_Connection=yes from your connection string. Right now, the string is giving a specific user name and password and also saying to use the pass-through Windows authentication. When running locally, your Windows account has rights to SQL (I assume), but in IIS, it is most likely logging on as anonymous.
I am trying to build a datagrid in Classic ASP. I have read a few articles here and there and am trying to use MSDataShape to implement this.
I have never worked with MSDataShape, so have absolutely no idea about it.
'Create the ADO Connection object.
set oCon = Server.CreateObject("ADODB.Connection")
'--- Generate the connection string
sCon = "Data Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;"
sCon = sCon & "Data Source=" & Server.MapPath("Northwind.mdb")
oCon.ConnectionString = sCon
'--- Specify that we will use the Data Shaping provider.
oCon.Provider = "MSDataShape"
'--- Open the connection
oCon.Open
I get the following error:
Microsoft OLE DB Service Components error '80040154' Class not
registered /DG/test.asp, line 39 –
The error message indicates that the data provider you specified can't be found. In this case, 3.51 is a very old version of Jet. Try using the following:
sCon = "Data Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;"
Also, if you're on a 64-bit OS, make sure you configure your application pool to run in 32-bit mode.
I have hosted a new website from www.hostingfarms.com. They have a file manager for uploading the website content and backup / restore DB (.bak) of MS SQL. I uploaded it. But when I log in into my website (www.theyuvaworld.com), database not gets connected. I have used this connection string in my local PC
SqlConnection con = new SqlConnection("server=.;database=test;integrated security=true");
SqlCommand cmd = new SqlCommand();
Should I make any changes here.
Note : I have created a user in file manager's database i.e Username = Nikhil and Password = **.
I will give any other details if wanted.
Regards,
Nikhil
I figured out this,
Connection string syntax is
data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true