|
Hello !
I have an application in vb.net 2013 , Entity Framework 6 and SQL server 200R2.
I' have finished the Program , but on the client computer , my program use a text based file called MyProg.exe.config , where are several lines .
But I don't like this text file because it's easily modifiable , and someone can change and the result may be a not working program.
Is there any way to not use ths file , and to save the data for example to a binary file that can be modified only from inside my program ?
The actual MyProg.exe.config has this contents :
="1.0"="utf-8"
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
</sharedListeners>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=USER-PC;initial catalog=DB1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyEntities2" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=User-PC;initial catalog=DB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Object" />
</assemblyBinding>
</runtime>
</configuration>
|
|
|
|
|
No, not realy. All of the built in configuration stuff expects the file to be there and in the format it is now.
But first, the Program Files folder, and everything under it, is ReadOnly to normal users. If everyone has admin permissions to their machines (really stupid idea!) then all you're doing is trying to protect the customer from themselves and that's a battle you're never going to win.
You don't have to put everything about your app in the app.config file. You can put all kinds of settings in your application Resources. They will no longer be editable, but the problem is that not even you are going to be able to edit them. You'll have to deploy a new .EXE if you update the settings you put in Resources.
modified 18-Jun-16 8:46am.
|
|
|
|
|
Thank you !
Maybe you're right for all that you wrote.
But let's suppose that for different reasons ( let's not talking about the reasons) , I need to eliminate this text based file.
It seems strange that programs created with vb.net requires a text based file. It seems an old way to hold the program's configuration data.
At least , I want to eliminate the part that hold the connection data for SQl server and Entity framework , because I want to let users configure these settings inside my application for example I will create a form that let users configure this settings and save this to a binary file.
I'm talking about this part :
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=USER-PC;initial catalog=DB1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyEntities2" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=User-PC;initial catalog=DB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
|
|
|
|
|
It has nothing to do with VB.NET
An XML file is editable, human readable, and a binary format would require another application in order to edit it. This would just be extra work on your part and quite a bit more difficult to get right, not to mention a pain in the ass when the structure of the file changes to support new options. You'd have to update the editor to match it and your code would also have to support multiple versions of a binary file.
But, if you want the extra work, there's nothing stopping you from writing your own configuration provider.
Just forget the binary file. It's actually the old way of storing data!
You can create your own settings in a file and save that to the users or the computers public data. You do not have to store it in app.config. You're going to have to read up on the ConfigurationManager class. You can create your own config file, separate from app.config, and store it in either the users profile or in the public profile that is common to all users on the machine. You can then tell the ConfigurationManager to load that config to get more settings, like your connection strings.
|
|
|
|
|
|
I have 163 data and bind in stringbuilder and convert into pdf but show only 162 data last data not show in pdf.
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Dim datStartDate As Date = calStartDate.SelectedDate
Dim datEndDate As Date = calEndDate.SelectedDate
Dim blnVisitsOnly As Boolean = cbxVisitsOnly.Checked
Dim intLisintFileCount As Integer = 0
If datStartDate > datEndDate Then
lblTestStatus.Text = "The start date must occur before the end date, please enter a valid start date."
Exit Sub
End If
'Retrieve Listing Data
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("BrokerLLCConnectionString1").ConnectionString.ToString)
Dim cmd As New SqlCommand()
If blnVisitsOnly = True Then
cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '') AND (VisitDate >= '" & datStartDate & "' AND VisitDate <= '" & datEndDate & "')"
cmd.Connection = conn
Else
cmd.CommandText = "SELECT DISTINCT t_Listing.Listing_ID, t_Listing.ListingName, l_NamePrefix.PrefixAbbrev, t_Individual.NameFirst, t_Individual.NameLast, ISNULL(t_Individual.Address, '') AS Address, ISNULL(t_Individual.City, '') AS City, t_Individual.State_ID, ISNULL(t_Individual.ZipCode, '') AS ZipCode, t_Business.BusinessName, l_Broker.NameFirstBroker + ' ' + l_Broker.NameLastBroker AS ListingAgent FROM t_Owner LEFT OUTER JOIN t_ListingVisit RIGHT OUTER JOIN t_Listing ON t_ListingVisit.Listing_ID = t_Listing.Listing_ID RIGHT OUTER JOIN t_Business ON t_Listing.Business_ID = t_Business.Business_ID ON t_Owner.Business_ID = t_Business.Business_ID RIGHT OUTER JOIN l_NamePrefix RIGHT OUTER JOIN t_Individual ON l_NamePrefix.NamePrefix_ID = t_Individual.NamePrefix_ID ON t_Owner.Individual_ID = t_Individual.Individual_ID LEFT OUTER JOIN l_Broker ON t_Individual.DesignatedBroker_ID = l_Broker.Broker_ID WHERE (t_Listing.Listing_ID <> '')"
cmd.Connection = conn
End If
Dim dr As SqlDataReader = Nothing
conn.Open()
dr = cmd.ExecuteReader()
Dim DT As New DataTable()
DT.Load(dr)
Dim sb As New StringBuilder()
sb.Append("<html xmlns='http://www.w3.org/1999/xhtml'>")
sb.Append("<head>")
sb.Append("</head>")
sb.Append("<body style=""font-family: Arial; color: #000000; font-size: medium;"">")
'sb.Append("")
sb.Append("")
'Dim k As Integer = 0
For i As Integer = 0 To DT.Rows.Count - 1
'k += 1
If i = 0 OrElse i Mod 3 = 0 OrElse i = DT.Rows.Count - 1 Then
sb.Append("")
' If i > 0 Then
' Else
' End If
'Else
End If
sb.Append("")
If i Mod 3 = 2 OrElse i = DT.Rows.Count - 1 Then
sb.Append(" ")
sb.Append("")
'k += 1
'If k = 10 Then
' Continue For
'End If
End If
'If (i Mod 3) = 0 AndAlso i > 0 Then
' sb.Append(" ")
' sb.Append("")
'End If
Next
sb.Append(" ")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append(DT.Rows(i)("PrefixAbbrev").ToString() + " " + DT.Rows(i)("NameFirst").ToString() + " " + DT.Rows(i)("NameLast").ToString())
sb.Append(" ")
sb.Append("")
sb.Append(If(Convert.ToString(DT.Rows(i)("Address").ToString()), If("", "", Convert.ToString(DT.Rows(i)("Address").ToString()))))
sb.Append(" ")
sb.Append("")
sb.Append(If(Convert.ToString(DT.Rows(i)("City").ToString()), If("", "", Convert.ToString(DT.Rows(i)("City").ToString()))))
sb.Append(", ")
sb.Append(If(Convert.ToString(DT.Rows(i)("State_ID").ToString()), If("", "", Convert.ToString(DT.Rows(i)("State_ID").ToString()))))
sb.Append(", ")
sb.Append(If(Convert.ToString(DT.Rows(i)("ZipCode").ToString()), If("", "", Convert.ToString(DT.Rows(i)("ZipCode").ToString()))))
sb.Append(" ")
sb.Append(" | ")
sb.Append(" |
")
'sb.Append(" ")
sb.Append("</body>")
sb.Append("</html>")
Dim sr As New StringReader(sb.ToString())
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=ExportedClientDocument.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim pdfDoc As New Document(PageSize.A4, 10, 5, 30, 50)
Dim htmlparser As New HTMLWorker(pdfDoc)
Dim pdfWriter__1 As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
End Using
End Using
End Sub
modified 17-Jun-16 5:25am.
|
|
|
|
|
|
I have two gridview dgvsource and dgvtarget.dgvsource have filled data through datasource below is my code to fill.
Private Sub populate_dgv()
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
conn = GetConnect()
conn.Open()
cmd.Connection = conn
Try
cmd.CommandText = "select Request_id,Request_date,Requestor,Destination,Department from tbeRequest r where r.request_id not in(select a.request_id from tbAssign_vehicle a)"
Dim Adpt As New SqlDataAdapter(cmd.CommandText, conn)
Dim ds As New DataSet()
Adpt.Fill(ds, "tbeRequest")
dgvsource.DataSource = ds.Tables("tbeRequest")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
1st gridview data is populated sucessfully.Then i have to copy selected row from 1st gridview to another gridview .Below is my code:
Private Sub dgvsource_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvsource.CellDoubleClick
Try
Dim i As Integer = 0
Dim Mylist As New List(Of Integer)
For Each row As DataGridViewRow In dgvsource.SelectedRows
Mylist.Add(row.Index)
Next
Mylist.Sort()
For Each index As Integer In Mylist
dgvtarget.Rows(i).Cells("request_id").Value = dgvsource.Rows(index).Cells("request_id").Value
i = i + 1
Next
Catch ex As Exception
End Try
End Sub
kindly help on this.
modified 17-Jun-16 4:20am.
|
|
|
|
|
i've this application that reads multiple files from a folder and upload them to the server..it works fine but when it wants to upload each file, it creates a connection, upload the file and closes the connection. it does the same thing for all the files over and over again. i want a situation where it creates just one connection, upload all the files and close the connection. please any help will be appreciated, i searched everywhere but couldnt find any help. below is my code
Imports System.IO
Imports System.Net
Public Class DemoFTPServerApp
Dim _Filename As String
Dim _UploadPath As String
Dim f As String
Public Sub LoadFiles(_User As String, _Password As String, _Path As String)
Dim _MyArraylist As New ArrayList
Dim FolderPath As String = "C:\Users\Desktop\files"
Dim finfo As New DirectoryInfo(FolderPath)
For Each fi In finfo.GetFiles("*.txt")
_MyArraylist.Add(fi.FullName) 'full path only
_Filename = fi.FullName
f = fi.ToString()
_UploadPath = _Path & f
Try
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri(_UploadPath)), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(_User, _Password)
request.UseBinary = True
request.UsePassive = False
request.KeepAlive = True
request.ConnectionGroupName = "company name"
request.ServicePoint.ConnectionLimit = 4
request.ServicePoint.CloseConnectionGroup("company name")
Dim buffer(1023) As Byte
Dim bytesIn As Long = 1
Dim filepath As System.IO.FileInfo = New System.IO.FileInfo(_Filename)
Dim _FileStream As System.IO.FileStream = filepath.OpenRead()
Dim _Stream As System.IO.Stream = request.GetRequestStream
Do Until bytesIn < 1
bytesIn = _FileStream.Read(buffer, 0, 1024)
If bytesIn > 0 Then
_Stream.Write(buffer, 0, bytesIn)
End If
Loop
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
MessageBox.Show("File Succesfully uploaded!")
End Sub
Private Sub btnUploadFile_Click(sender As Object, e As EventArgs) Handles btnUploadFile.Click
LoadFiles("username", "password", "ftp://ftpsite.com/")
End Sub
|
|
|
|
|
Hello !
In a vb.net program that use a sql server database , is there a way to keep the database file in Program's folder instead of default sql server's Data folder ?
Thank you !
|
|
|
|
|
Yes, but the Program Folder is not meant for data, it is meant for applications. Data goes in the users' documents folder.
It may require administrative rights to make modifications in the Program Folder; meaning that any user using it would have to run in an administrative role.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|
Depends on your client; in my case you'd need at least bribe the sysadmin, otherwise there will not be a folder in the root of the drive. Also, data is "expected" to be in the documents folder for both backup-applications as well as migrations.
If you "create database", you have multiple options on where to store you datafiles and how large they are allowed to become. More info on MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Everying under Program Files is read-only to to normal users. It's not a good idea to put your database in there.
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|
Putting your program off the root of C: will just piss off system admins. Permission control becomes an issue with them and results in more work.
Unless the SQL Server is local on the machine, you really don't have control over where the file goes.
But, if it is local, you have to execute the query to create a database manually and tell SQL Server where to put the files. Assuming SQL Server, you have to attach to the master database in your connection string and then execute the following SQL against it:
CREATE DATABASE MyDatabase
ON
( NAME = N'MyDatabase_data',
FILENAME = N'C:\MyProgram1\MyDatabaseData.mdf',
SIZE = 100,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5 )
LOG ON
( NAME = N'MyDatabase_log',
FILENAME = N'C:\MyProgram1\MyDatabaselog.ldf',
SIZE = 100,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5 )
All sizes are in MB by default. You can read up more on the CREATE DATABASE statement in the documentation[^].
|
|
|
|
|
If it's an existing database:
1) "Detach it" in Management Studio
2) Copy from the default location to the desired location
3) "Attach it" in Management Studio from the new location
|
|
|
|
|
Ok , but your steps are not the real scenario that I want.
- I have the program folder.
- The databases are inside the program folder.
- I open the program.
- The databases should be attached from the program automatically.
- When I close the program the databases should be detached automatically
|
|
|
|
|
"Connection strings" are used to "connect" programs and SQL Server databases.
You do not seem to know the difference between "attaching" a database to SQL Server and "connecting" a program and a database.
|
|
|
|
|
I want that the databases to be not be visible under SQL management studio , when my program is not open.
|
|
|
|
|
desanti wrote: I want that the databases to be not be visible under SQL management studio Well that is not going to happen, you can't manage the SSMS application in your app.
What you can do is set permissions on your database so it requires credentials to OPEN your database. It will still be visible but non credentialed users will not be able to access it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sorry , but you get just a part of my words and try to comment them as you want.
I've said :
Quote: I want that the databases to be not be visible under SQL management studio , when my program is not open.
This is the full scenario :
- My program is installed on the client's computer.
- The databases are on my program folder ( not in default sql server's data folder )
- At this time the databases are not visible on Sql server management studio.
- I open the program , and at this point I want to attach my databases.
- After I connect to these databases.
- When I close the program , I want to close the connection with databases.
- After I want to completely detach them , so they will not visible on SQL server management studo.
Is it possible to realize this scenario ?
Thank you !
|
|
|
|
|
Actually you don't understand how a database management system works.
In SSMS a database needs to be attached to the server, any user with adequate permissions can attach a database including yours no matter where it resides. You cannot stop a user from attaching a database!
You can stop a user from accessing your database using the standard security functions in SQL Server.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
Is it possible to separate each project's form in different dll files , and to call them when needed ?
To be more clear , currently when the project is compiled , an .exe file is created and all the code related to different forms are inside the .exe.
Is it possible to change this behavior , so on exe to have only the main's form code , that just call other forms from dll files ?
Thank you !
|
|
|
|
|
Yes it is but at a cost of increased complexity.
You'd have to create a class library project for each of your forms. The class files in those projects should be changed immediately to inherit from System.Windows.Forms.Form. It's then possible to open them up in the designer and drop controls on them.
You're also going to have to change the InitializeComponent() method in each of those forms from "private" to "public" so you can call it from the calling form. This will setup the controls on the new form so that they are visible.
You then have to go back the project that's going to use this form and add a project reference to each of the forms that this form is going to use. You then can create a new instance of the form but you're going to have to initialize it yourself, something like this:
using (var newForm = new Form2.Form2())
{
form2.InitializeComponent();
form2.ShowDialog();
}
I don't see any benefit that outways the complexity of doing this, so what's the point?
|
|
|
|
|