|
Hi all,
I have a problem with that instruction: For Each f In IO.Directory.GetFiles(sDir)
sDir = "R:\Temp" for example.
When I use that on a local directory on the C:\ driva it works ok, but when I try to use that on the network with a mapped drive (example: R:\Temp) I get the error: System.IO.DirectoryNotFoundException: Could not find a part of the path R:\Temp
Can you help me?
Thanks!!!!
|
|
|
|
|
use complete UNC path rather than your map drive path. IT will solve the problem
Abhishek Sur
|
|
|
|
|
When I use the complete UNC (for example: \\MyServer\Data\xxx\ ) I have a new problem: System.IO.IOException: Logon failure: unknown user name or bad password.
Is there any other way of listing the files on a network drive?
|
|
|
|
|
Finally I solved the logon problem with those lines of code in the web.config
<authentication mode="Windows">
<identity impersonate="true">
It works ok with thw complete UNC.
Thanks for your help!!
|
|
|
|
|
Can you explain your solution with a bit more detail about the changes to the web.config?
Thanks,
Patrick
|
|
|
|
|
Yes, I added this lines of code to the web.config so the denny access message is solved:
<br />
<authentication mode="Windows" /><br />
<br />
<identity impersonate="true"/><br />
<br />
Now the directories are listed ok in my code:
<br />
For Each f In IO.Directory.GetFiles(sDir)<br />
Dim myList As New ListItem<br />
If f.EndsWith(".xls") Then<br />
Dim intPosicion As Integer<br />
intPosicion = f.LastIndexOf("\")<br />
myList.Text = f.Substring(intPosicion + 1)<br />
lstPaths1.Items.Add(myList)<br />
End If<br />
Next<br />
Here I list all the filenames that ends with .xls and put it into a listbox.
Did you understand now?
Sorry english is not my language..I speak spanish.
|
|
|
|
|
Good Afternoon
My Application is Structured in a Way that before you login you must First Select a Database. Now i have one page that i want to change the Connection String Database name.
I have this function that get called on page load
public void UpdateConfig()
{
CommonFunctions obj = new CommonFunctions();
String strKey = "NEWDT";
String StrDatabase;
if (Session["ActiveDatabase"] != null)
{
StrDatabase = Convert.ToString(Session["ActiveDatabase"]);
}
else
{
StrDatabase = "oDirectv3";
}
String strValue = @"User id=sa;Password=abacus;Server=LOUWTJIE\SQLEXPRESSDatabase="+StrDatabase;
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
if (objAppsettings != null)
{
objAppsettings.Settings[strKey].Value = strValue;
objConfig.Save();
}
}
On the Development site it works well. But while still debugging the code, checking if its doing what i want, There is a point where it has to save the changes
objConfig.Save();
The Part will execute and message box will appear asking me if i really want to save the changes made, i will save yes and everything will be fine. But if i don debug it , it gives an Error that says
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
How can i do this and Suppress this dialogs
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
You're going about this all wrong. You cant possible update the web.config for every different session - the reason it works in development is because you are the only session. Once this goes into a multi-user environment I cant see how it would operate sucessfully.
I have a similar issue in an app I am writing, and I configure using separate connection strings in the web config and make a decision which one to use at run-time based on the user's settings.
|
|
|
|
|
Man, you beat me to the punch by seconds
var question = (_2b || !(_2b));
|
|
|
|
|
Good Afternoon J4amieC
I have Created a Connection String for this. Now the Connection String Difference is only on the Database part. So i need to change the Database name Before doing anything.
Please Advice on the Best way of doing this
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Well I wouldn't go about changing web.config, for one thing...
Because if another user starts up the same website, they're gonna change the web.config again, aren't they?
Or, if they're picking a database on page_load, have as many connection strings in the web.config as you need, and use that one ( a simple switch-case statement will define which one you want).
But changing the connection string in the web.config through your application seems very insecure to me.
You have to remember web.config is the whole application's configuration, not its one instance.
var question = (_2b || !(_2b));
|
|
|
|
|
Greg Wrote:
Well I wouldn't go about changing web.config, for one thing...
Because if another user starts up the same website, they're gonna change the web.config again, aren't they?
yes
Please Give advice on how to do it
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
There's honestly a lot of ways you could it.
The cleanest would be to add all the connection strings into the webconfig (using
<connectionStrings>
<add name="string1" connectionString="datasource=.\SQLEXPRESS;User ID=sa;password=1235;Database=Database1" providername="System.Data.SqlClient" />
<add name="string2" connectionString="datasource=.\SQLEXPRESS;User ID=sa;password=1235;Database=Database2" providername="System.Data.SqlClient" />
</connectionStrings>
There is another, though. You can set up one connection string and then when you reference it in the code you do:
string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
connString = connString.Replace("Database1", "YourDataBaseName");
var question = (_2b || !(_2b));
|
|
|
|
|
Thanks for your Advice
Now the Second Option,can work for me. But i have a Question regarding the replace part.
The "YourDataBaseName" does it matter if it comes from a Session variable ?
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Vuyiswa Maseko wrote: The "YourDataBaseName" does it matter if it comes from a Session variable ?
Nope.
As long as it's a string!
var question = (_2b || !(_2b));
|
|
|
|
|
hi Greg
i Done it this way
<connectionStrings>
<add name="string1" connectionString="datasource=VUYISWA_SERVER ;User ID=VA;password=MASEKO;Database=NEWDT" providerName="System.Data.SqlClient" />
</connectionStrings>
And the C# code is like this
public void UpdateConfig()
{
String StrDatabase;
if (Session["ActiveDatabase"] != null)
{
StrDatabase = Convert.ToString(Session["ActiveDatabase"]);
string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
connString = connString.Replace("NEWDT", StrDatabase);
}
else
{
StrDatabase = "oDirectv3";
string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
connString = connString.Replace("NEWDT", StrDatabase);
}
}
And am Calling this Function like this from a page load
protected void Page_Load(object sender, EventArgs e)
{
Session["ActiveDatabase"] = "Mafutha";
UpdateConfig();
Response.Write("<script> alert('Wow i did it');</script>");
}
Remember this is just a test to see if it will change the Database in the Connection String. After i run it i get the alert no Errors but the Connection String has not been changed to "Mafutha".
What could be the Problem ?
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
OK, now look.
Obviously, your UpdateConfig() method is not going to physically alter the web.config.
The connection string you want to use is only going to work with just one session, and that's a good thing. Instead of keeping just the database name in your session variable, store the whole connection string.
If you do not want to, change your UpdateConfig() method (and change its name too, cos it's confusing) like so:
private string GetConnectionString(string DB)
{
string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
if (Session["ActiveDatabase"] != null)
{
return connString.Replace("NEWDT", DB);
}
else
{
return connString.Replace("NEWDT", "oDirectv3");
}
}
Anytime you want to use the connection string, just call this function to return it to you.
var question = (_2b || !(_2b));
|
|
|
|
|
Good Day Greg
I would like to take this chance and thank you for what you have doe for me. Everything is Working Fine.
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Hi friends,
I got a question that
"Can i use my own SQl Databse Table named 'RegisteredUsers' to store the information about users who wants to register on my site. If i used my own class like such without using the ASPMembershipProvider then is there any drawback of using my method."
As i have this table "Registered Users" and its class that will handle all the information about the user.
Thanks in advance if any one can answer.
Cause i m confused about my using wether my own structures, Methods and classes OR just to use the ASPMembershipProvider for the user login and registration.
|
|
|
|
|
Yes ... no problem with that ... We generally use own custom database for Registered user and dont use ASPMembershipProviders.
Rather it is better to create a Web Interface for login, probably you can use Web service for login if you want
|
|
|
|
|
I got this error during debugging the code without using an IIS or webserver. I got two errors ,
1.
Line 105:<compilers>
Line 106:<compiler language="c#;cs;csharp" extension=".cs" warninglevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Line 107:<provideroption name="CompilerVersion" value="v3.5">
Line 108:<provideroption name="WarnAsError" value="false">
Line 109:
--the bolded session will have the error.
2. child notes not allowed.
Help me please!
|
|
|
|
|
Really you have not Specified your Problem.
Tell us what were you trying to do before the Error occurred. and post us the Error the way it appears
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Currently I need to write a code To Import data from Excel sheet to sql Database-asp.net 2.0
I Have Written A function For It
Function Is Given Below ;
But as i execute it it gives Error Meaasge
"The Microsoft Jet database engine cannot open the file 'D:\'. It is already opened exclusively by another user, or you need permission to view its data."
I Have Order.xls File In D Drive
protected void btnUpload_Click1(object sender, EventArgs e)
{
string PathtoTextFile = ("D:\\");
Response.Write(PathtoTextFile);
System.Data.OleDb.OleDbConnection oCon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\;Extended Properties= \"Excel 8.0;HDR=no;IMEX=1 \"");
System.Data.OleDb.OleDbDataAdapter oCmd = new System.Data.OleDb.OleDbDataAdapter("select * from Order.xls", oCon);
DataSet myDS = new DataSet();
oCmd.Fill(myDS);
oCon.Close();
}
Raghvendra
|
|
|
|
|
You need to pass the filename in the data source, in the connection string, dude.
You're on the right path, though.
And then, the sql you wrote ("select * from Order.xls") should really be ("select * from Sheet1"), or whatever your Sheet is called in that excel spreadsheet.
The rest seems fine... Except I would use a DataTable, and not a DataSet.
Easier that way
var question = (_2b || !(_2b));
|
|
|
|
|
Thanks For Reply,
I did the same as u instructed ,
But Still Having Same Error
Raghvendra
|
|
|
|